Open History to see the last commit
1import React from 'react'
2import ReactDOM from 'react-dom/client'
3import { RouterProvider, createRouter } from '@tanstack/react-router'
4β
5import { routeTree } from './routeTree.gen'
6import { AuthContextProvider, useAuth } from './auth'
7β
8import './styles.css'
9β
10// Set up a Router instance
11const router = createRouter({
12 routeTree,
13 defaultPreload: 'intent',
14 scrollRestoration: true,
15 context: {
16 auth: undefined!, // This will be set after we wrap the app in AuthContextProvider
17 },
18})
19β
20// Register things for typesafety
21declare module '@tanstack/react-router' {
22 interface Register {
23 router: typeof router
24 }
25}
26β
27function InnerApp() {
28 const auth = useAuth()
29β
30 // If the provider is initially loading, do not render the router
31 if (auth.isInitialLoading) {
32 return (
33 <div className="flex h-screen w-full items-center justify-center p-4">
34 <div className="size-10 rounded-full border-4 border-gray-200 border-t-foreground animate-spin" />
35 </div>
36 )
37 }
38β
39 return <RouterProvider router={router} context={{ auth }} />
40}
41β
42function App() {
43 return (
44 <AuthContextProvider>
45 <InnerApp />
46 </AuthContextProvider>
47 )
48}
49β
50const rootElement = document.getElementById('app')!
51β
52if (!rootElement.innerHTML) {
53 const root = ReactDOM.createRoot(rootElement)
54 root.render(
55 <React.StrictMode>
56 <App />
57 </React.StrictMode>,
58 )
59}