Components
TanStack Start provides specialized React components for building full-stack applications.StartClient
StartClient is the root client component that hydrates your application in the browser.
Usage
How It Works
TheStartClient component:
- Calls
hydrateStart()to restore the router state from the server - Wraps your application with
RouterProvider - Uses
Awaitto handle the hydration promise - Signals when hydration is complete for cleanup
StartServer
StartServer is the root server component used during server-side rendering.
Usage
How It Works
StartServer is a thin wrapper around RouterProvider for the server:
Entry Points
Client Entry
Your client entry file renders theStartClient component:
Server Entry
Your server entry file usesStartServer for SSR:
Hydration
The hydration process seamlessly transfers state from server to client.hydrateStart
ThehydrateStart function restores the router instance on the client:
Hydration Flow
- Server: Router state is serialized and embedded in the HTML
- Client:
hydrateStart()deserializes the state - Client: Router is initialized with the restored state
- Client: React hydrates the DOM without re-rendering
- Cleanup: Hydration signal triggers any necessary cleanup
Router Integration
Start components integrate with TanStack Router components:Scripts Component
TheScripts component injects client bundles into your HTML:
Head Management
Manage document head withHeadContent:
Streaming
Stream HTML and data to the client:Deferred Data
UseAwait and Suspense for deferred data loading:
Error Boundaries
Handle errors with error boundaries:Not Found
Handle 404 errors:Best Practices
Single Root Component
UseStartClient once at your application root:
Server vs Client Imports
Use the correct import for each environment:Document Structure
Always render a complete HTML document:Hydration Mismatch
Avoid hydration mismatches by ensuring server and client render the same content:API Reference
StartClient
Client-side root component. Props: None Example:StartServer
Server-side root component. Props:router:AnyRouter- Router instance
hydrateStart
Hydrates the router on the client. Returns:Promise<AnyRouter>
Example:
Related
- Server Functions - Creating server functions
- Client Functions - Client-side utilities
- Router Documentation - TanStack Router