- Spec files
npm-tanstack--react-start
Describes: pkg:npm/@tanstack/react-start@1.131.x
- Description
- SSR, Streaming, Server Functions, API Routes, bundling and more powered by TanStack Router and Vite. Ready to deploy to your favorite hosting provider.
- Author
- tessl
- Last updated
How to use
npx @tessl/cli registry install tessl/npm-tanstack--react-start@1.131.0
index.md docs/
1# TanStack React Start23TanStack React Start is a full-stack React framework that provides SSR (Server-Side Rendering), streaming, server functions, API routes, and bundling capabilities. Built on top of TanStack Router and Vite, it offers type-safe routing with built-in caching and URL state management for modern React applications with seamless deployment to various hosting providers.45## Package Information67- **Package Name**: @tanstack/react-start8- **Package Type**: npm9- **Language**: TypeScript10- **Installation**: `npm install @tanstack/react-start`11- **Peer Dependencies**: React 18+/19+, Vite 6+, @vitejs/plugin-react 4.3.4+1213## Core Imports1415**Client-side (default import)**:16```typescript17import { StartClient, useServerFn, createServerFn } from "@tanstack/react-start";18```1920**Explicit client import**:21```typescript22import { StartClient, useServerFn, createServerFn } from "@tanstack/react-start/client";23```2425**Server-side**:26```typescript27import { StartServer, defaultStreamHandler, createStartHandler } from "@tanstack/react-start/server";28```2930**Vite plugin**:31```typescript32import { TanStackStartVitePlugin } from "@tanstack/react-start/plugin/vite";33```3435**Server functions**:36```typescript37// Client-side server function calls38import { createClientRpc } from "@tanstack/react-start/server-functions-client";3940// Server-side server function handlers41import { createServerRpc } from "@tanstack/react-start/server-functions-server";42```4344## Basic Usage4546### Client Application Setup4748```typescript49import { StrictMode, startTransition } from 'react';50import { hydrateRoot } from 'react-dom/client';51import { StartClient } from '@tanstack/react-start';52import { createRouter } from './router'; // Your router configuration5354const router = createRouter();5556startTransition(() => {57hydrateRoot(58document,59<StrictMode>60<StartClient router={router} />61</StrictMode>62);63});64```6566### Server Application Setup6768```typescript69import { createStartHandler, defaultStreamHandler } from '@tanstack/react-start/server';70import { createRouter } from './router'; // Your router configuration7172export default createStartHandler({73createRouter,74})(defaultStreamHandler);75```7677### Vite Configuration7879```typescript80import { defineConfig } from 'vite';81import { TanStackStartVitePlugin } from '@tanstack/react-start/plugin/vite';8283export default defineConfig({84plugins: [85TanStackStartVitePlugin({86// Configuration options87}),88],89});90```9192### Server Functions9394```typescript95import { createServerFn } from '@tanstack/react-start';96import { useServerFn } from '@tanstack/react-start';9798// Define a server function99const getUser = createServerFn().handler(async (userId: string) => {100// This runs on the server101return await fetchUserFromDatabase(userId);102});103104// Use in a React component105function UserProfile({ userId }: { userId: string }) {106const serverFn = useServerFn(getUser);107108const handleClick = async () => {109const user = await serverFn(userId);110console.log(user);111};112113return <button onClick={handleClick}>Load User</button>;114}115```116117## Architecture118119TanStack React Start is built around several key architectural patterns:120121- **Full-Stack Type Safety**: Complete TypeScript integration from client to server with shared type definitions122- **Server Functions**: Type-safe RPC-style communication between client and server code123- **SSR/Streaming**: Built-in server-side rendering with streaming support for optimal performance124- **File-Based Routing**: Leverages TanStack Router's file-based routing with server-side route support125- **Vite Integration**: Deep integration with Vite for modern development experience and optimized builds126- **Middleware System**: Comprehensive middleware support for server functions with validation and context passing127- **Serialization**: Custom serialization system for complex data types between client and server128129## Capabilities130131### Client-Side Framework132133Core client-side functionality including the main application component, React hooks for server function integration, and client-side utilities for full-stack applications.134135```typescript { .api }136function StartClient(props: { router: AnyRouter }): JSX.Element;137138function useServerFn<T extends (...deps: Array<any>) => Promise<any>>(139serverFn: T140): (...args: Parameters<T>) => ReturnType<T>;141```142143[Client-Side Framework](./client.md)144145### Server-Side Rendering146147Server-side rendering components, streaming handlers, and utilities for processing requests and generating responses with full React Server Components support.148149```typescript { .api }150function StartServer<TRouter extends AnyRouter>(props: {151router: TRouter152}): JSX.Element;153154function createStartHandler(options: {155createRouter: () => AnyRouter;156}): (handler: HandlerCallback) => HandlerCallback;157158const defaultStreamHandler: HandlerCallback;159const defaultRenderHandler: HandlerCallback;160```161162[Server-Side Rendering](./server.md)163164### Server Functions165166Type-safe server function system enabling seamless communication between client and server code with middleware support, validation, and automatic serialization.167168```typescript { .api }169function createServerFn<TValidator = undefined, TMiddleware = []>(170options?: ServerFnBaseOptions<TValidator, TMiddleware>171): ServerFnBuilder<TValidator, TMiddleware>;172173function createIsomorphicFn<TArgs extends Array<any>, TReturn>(174clientFn: (...args: TArgs) => TReturn,175serverFn: (...args: TArgs) => TReturn176): IsomorphicFn<TArgs, TReturn>;177178function createMiddleware<TOptions extends FunctionMiddlewareOptions>(179options: TOptions180): FunctionMiddlewareWithTypes<TOptions>;181```182183[Server Functions](./server-functions.md)184185### Vite Build Integration186187Vite plugin for seamless integration with the Vite build system, providing automatic code splitting, server-side entry generation, and development server configuration.188189```typescript { .api }190function TanStackStartVitePlugin(191opts?: TanStackStartInputConfig & WithReactPlugin192): Array<PluginOption>;193194interface TanStackStartInputConfig {195react?: ViteReactOptions;196customViteReactPlugin?: boolean;197}198```199200[Vite Build Integration](./vite-plugin.md)201202## Core Types203204```typescript { .api }205interface AnyRouter {206state: {207matches: Array<any>;208location: any;209};210navigate: (options: any) => Promise<any>;211resolveRedirect: (redirect: any) => { options: any };212}213214interface HandlerCallback {215(context: {216request: Request;217router: AnyRouter;218responseHeaders: Headers;219}): Response | Promise<Response>;220}221222interface ServerFnBaseOptions<TValidator, TMiddleware> {223method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';224validator?: TValidator;225middleware?: TMiddleware;226}227228interface IsomorphicFn<TArgs extends Array<any>, TReturn> {229(...args: TArgs): TReturn;230}231232type PluginOption = {233name: string;234configEnvironment?: () => any;235[key: string]: any;236};237```