Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

client-entry-point.md

71 lines1.9 KB

1---
2id: client-entry-point
3title: Client Entry Point
4---
5​
6> [!NOTE]
7> The client entry point is **optional** out of the box. If not provided, TanStack Start will automatically handle the client entry point for you using the below as a default.
8​
9Getting our html to the client is only half the battle. Once there, we need to hydrate our client-side JavaScript once the route resolves to the client. We do this by hydrating the root of our application with the `StartClient` component:
10​
11```tsx
12// src/client.tsx
13import { StartClient } from '@tanstack/react-start/client'
14import { StrictMode } from 'react'
15import { hydrateRoot } from 'react-dom/client'
16​
17hydrateRoot(
18 document,
19 <StrictMode>
20 <StartClient />
21 </StrictMode>,
23```
24​
25This enables us to kick off client-side routing once the user's initial server request has fulfilled.
26​
27## Error Handling
28​
29You can wrap your client entry point with error boundaries to handle client-side errors gracefully:
30​
31```tsx
32// src/client.tsx
33import { StartClient } from '@tanstack/react-start/client'
34import { StrictMode } from 'react'
35import { hydrateRoot } from 'react-dom/client'
36import { ErrorBoundary } from './components/ErrorBoundary'
37​
38hydrateRoot(
39 document,
40 <StrictMode>
41 <ErrorBoundary>
42 <StartClient />
43 </ErrorBoundary>
44 </StrictMode>,
46```
47​
48## Development vs Production
49​
50You may want different behavior in development vs production:
51​
52```tsx
53// src/client.tsx
54import { StartClient } from '@tanstack/react-start/client'
55import { StrictMode } from 'react'
56import { hydrateRoot } from 'react-dom/client'
57​
58const App = (
59 <>
60 {import.meta.env.DEV && <div>Development Mode</div>}
61 <StartClient />
62 </>
64​
65hydrateRoot(
66 document,
67 import.meta.env.DEV ? <StrictMode>{App}</StrictMode> : App,
69```
70​
71The client entry point gives you full control over how your application initializes on the client side while working seamlessly with TanStack Start's server-side rendering.