Skip to main content

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

The StartClient component:
  1. Calls hydrateStart() to restore the router state from the server
  2. Wraps your application with RouterProvider
  3. Uses Await to handle the hydration promise
  4. 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 the StartClient component:

Server Entry

Your server entry file uses StartServer for SSR:

Hydration

The hydration process seamlessly transfers state from server to client.

hydrateStart

The hydrateStart function restores the router instance on the client:

Hydration Flow

  1. Server: Router state is serialized and embedded in the HTML
  2. Client: hydrateStart() deserializes the state
  3. Client: Router is initialized with the restored state
  4. Client: React hydrates the DOM without re-rendering
  5. Cleanup: Hydration signal triggers any necessary cleanup

Router Integration

Start components integrate with TanStack Router components:

Scripts Component

The Scripts component injects client bundles into your HTML:

Head Management

Manage document head with HeadContent:

Streaming

Stream HTML and data to the client:

Deferred Data

Use Await and Suspense for deferred data loading:

Error Boundaries

Handle errors with error boundaries:

Not Found

Handle 404 errors:

Best Practices

Single Root Component

Use StartClient 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
Example:

hydrateStart

Hydrates the router on the client. Returns: Promise<AnyRouter> Example: