Open History to see the last commit
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>,
22)
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>,
45)
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 </>
63)
64β
65hydrateRoot(
66 document,
67 import.meta.env.DEV ? <StrictMode>{App}</StrictMode> : App,
68)
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.