Skip to content

truongnat/example-react

Repository files navigation

TanStack Full Demo

A beginner-friendly dashboard showcasing all major TanStack libraries working together in a real app.

πŸ”— Live Demo: https://example-react-brown.vercel.app

TanStack Libraries Used

Library Version Usage
@tanstack/react-router ^1.167.4 File-based routing, type-safe navigation, SSR
@tanstack/react-query ^5.90.21 Data fetching, caching, useQuery + useMutation
@tanstack/react-table ^8.21.3 Headless table β€” sort, filter, pagination
@tanstack/react-virtual ^3.13.23 Virtualized list for large datasets
@tanstack/react-form ^1.28.5 Form state management with validation
@tanstack/react-store ^0.9.2 Global UI state (tab, view mode, search)
@tanstack/react-start ^1.166.15 Full-stack React framework (SSR)

Pages

🟣 /todos β€” Query + Form + Store

  • useQuery to fetch todos with automatic caching
  • useMutation for add / toggle / delete with optimistic updates (UI updates instantly, reverts on error)
  • useForm with field-level validation (required field)
  • @tanstack/store for global search state shared across components

πŸ”΅ /posts β€” Query + Table + Virtual

  • useQuery fetches all 100 posts once, cached for 10 minutes
  • useReactTable with sorting (click headers), global filter, and pagination
  • Toggle to Virtual List mode β€” useVirtualizer renders only visible rows in DOM (~5-10 rows), not all 100

🟒 /users β€” Query + Table + Form

  • Sortable, filterable table of 10 users
  • Click ✏️ to open edit dialog
  • useForm inside dialog with per-field validation
  • useMutation patches user with optimistic update

Key Concepts Demonstrated

  • Optimistic Updates β€” UI reflects changes immediately without waiting for API
  • Cache Invalidation β€” mutations cancel in-flight queries and update cache directly
  • SSR-safe hooks β€” useStore with explicit selectors, QueryClient created per-request on server
  • Virtualization β€” 100 rows in DOM = ~10 elements vs 100 with normal rendering
  • Headless UI β€” TanStack Table/Form/Virtual are logic-only, you own the markup

Tech Stack

  • TanStack Start (@tanstack/react-start) β€” SSR framework
  • Vite + Nitro β€” bundler & server (Vercel preset)
  • shadcn/ui β€” Radix UI + CVA components (Button, Card, Input, Badge, Dialog, Checkbox...)
  • Tailwind CSS v4 β€” utility-first styling with @theme CSS variables
  • Lucide React β€” icons
  • JSONPlaceholder β€” free fake REST API (todos, posts, users)
  • TypeScript throughout

Project Structure

src/
β”œβ”€β”€ components/
β”‚   └── ui/               # shadcn/ui components
β”‚       β”œβ”€β”€ button.tsx
β”‚       β”œβ”€β”€ card.tsx
β”‚       β”œβ”€β”€ input.tsx
β”‚       β”œβ”€β”€ badge.tsx
β”‚       β”œβ”€β”€ checkbox.tsx
β”‚       β”œβ”€β”€ dialog.tsx
β”‚       β”œβ”€β”€ label.tsx
β”‚       β”œβ”€β”€ select.tsx
β”‚       └── separator.tsx
β”œβ”€β”€ lib/
β”‚   └── utils.ts          # cn() helper (clsx + tailwind-merge)
β”œβ”€β”€ store/
β”‚   └── index.ts          # @tanstack/store global state
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ __root.tsx        # Root layout (QueryClientProvider, Header, Outlet)
β”‚   β”œβ”€β”€ index.tsx         # Home dashboard
β”‚   β”œβ”€β”€ todos.tsx         # Query + Form + Store demo
β”‚   β”œβ”€β”€ posts.tsx         # Table + Virtual demo
β”‚   └── users.tsx         # Table + Form + Mutation demo
β”œβ”€β”€ styles/
β”‚   └── app.css           # Tailwind v4 + shadcn CSS variables
β”œβ”€β”€ router.tsx            # createRouter config
└── routeTree.gen.ts      # Route tree (manually maintained)

Getting Started

git clone https://github.com/truongnat/example-react
cd example-react
npm install
npm run dev

Open http://localhost:3000

Deploy

Pre-configured for Vercel β€” just connect the repo on vercel.com, no extra settings needed.

Uses Nitro vercel preset which outputs to .vercel/output/ format automatically.

Note: JSONPlaceholder is a read-only fake API. Mutations (add/edit/delete) return correct responses but data resets on page reload.

About

TanStack Full Demo β€” Query, Table, Virtual, Form, Store, Router in one app. Built with TanStack Start + shadcn/ui + Tailwind v4

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors