|
| 1 | +# tanstack-db-react-query-template |
| 2 | + |
| 3 | +## Overview |
| 4 | +This Vite-powered template pairs TanStack React Query with TanStack DB layer to showcase optimistic updates and live queries in app. |
| 5 | +It bootstraps a mock-backed users table, wiring collection sync, optimistic mutations and client-side pagination so you can explore the data workflows before pointing at a real API. |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | +- Node.js 24+ |
| 9 | + |
| 10 | +## Getting Started |
| 11 | +1. Install dependencies: `npm install` |
| 12 | +2. Launch the dev server with hot reload: `npm run dev` |
| 13 | +3. Visit the printed URL (default `http://localhost:5173`) to interact with the demo |
| 14 | +4. Build assets when ready to deploy or share: `npm run build` |
| 15 | +5. Optionally preview the built bundle locally: `npm run preview` |
| 16 | + |
| 17 | +## Project Structure |
| 18 | +```text |
| 19 | +. |
| 20 | +├─ dist/ # Generated Vite build output (ignored in source control) |
| 21 | +├─ src/ |
| 22 | +│ ├─ api/ |
| 23 | +│ │ ├─ client/ # Shared QueryClient instance |
| 24 | +│ │ ├─ handlers/ # Mock REST handlers simulating backend behavior |
| 25 | +│ │ └─ types/ # TypeScript DTOs for API payloads |
| 26 | +│ ├─ db/ # TanStack DB collections and sync helpers |
| 27 | +│ ├─ hooks/ # Reusable hooks for data fetching and mutations |
| 28 | +│ ├─ App.tsx # Users table UI and pagination logic |
| 29 | +│ └─ index.tsx # React entry point and root render |
| 30 | +├─ eslint.config.mjs # Project-wide ESLint configuration (Nimbus Clean preset) |
| 31 | +├─ package.json # Scripts, dependencies, and metadata |
| 32 | +├─ tsconfig.json # TypeScript compiler options |
| 33 | +└─ vite.config.ts # Vite build and dev server configuration |
| 34 | +``` |
| 35 | + |
| 36 | +## Available Commands |
| 37 | +- `npm run dev` — start the Vite dev server with hot module replacement |
| 38 | +- `npm run build` — type-check with project references, then emit a production bundle to `dist/` |
| 39 | +- `npm run preview` — serve the latest build output for manual smoke testing |
| 40 | +- `npm run lint` — run ESLint on all `.ts`/`.tsx` sources using the configured presets |
| 41 | +- `npm run lint:fix` — apply ESLint auto-fixes where possible |
| 42 | +- `npm run typecheck` — run TypeScript in no-emit mode to surface typing regressions |
| 43 | + |
| 44 | +## Development Notes |
| 45 | +The demo uses mock user data from `src/api/handlers/users.mock.ts`. |
| 46 | +Replace these handlers with real API calls as you integrate a backend. |
| 47 | +Collections in `src/db` must be ready (`ensureUsersCollectionIsReady`) before mutating to keep TanStack DB and React Query in sync. |
0 commit comments