A modern React application demonstrating the integration of React 19's use
hook with Zustand state management for API data fetching.
- React 19: Latest React version with the new
use
hook - Vite: Fast development server and build tool
- TypeScript: Type-safe development
- Zustand: Lightweight state management with best practices
- API Integration: Dummy API with loading, success, and error states
- Modern UI: Clean and responsive design
- React 19.1.0
- Vite 7.0.3
- TypeScript 5.8.3
- Zustand (latest)
- Immer (for immutable state updates)
src/
├── components/
│ └── ApiDataDisplay.tsx # Component using React's "use" hook
├── hooks/
│ └── useApiData.ts # Custom hook for API data management
├── services/
│ └── api.ts # API service with dummy data
├── store/
│ └── apiStore.ts # Zustand store with best practices
├── types/
│ └── api.ts # TypeScript types
├── App.tsx # Main application component
└── main.tsx # Application entry point
- Middleware: Uses
devtools
,subscribeWithSelector
, andimmer
- Type Safety: Full TypeScript support
- Selectors: Optimized selectors for performance
- Actions: Async actions with proper error handling
- State Management: Loading, error, and success states
- Integrates with Zustand store
- Handles suspense and error boundaries
- Provides clean data fetching patterns
- Simulates real API delays (1.5 seconds)
- Random error simulation (20% error rate)
- Mock user data similar to JSONPlaceholder
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
Open your browser and navigate to
http://localhost:5173
- Click "Fetch Users" to load data from the API
- Watch the loading state with spinner
- See success state with user cards
- Experience error handling (20% chance of error)
- Use "Clear Error" to dismiss errors
- Use "Reset" to clear all data
fetchUsers()
: Fetch users from APIclearError()
: Clear error statereset()
: Reset store to initial state
useUsers()
: Get users arrayuseLoading()
: Get loading stateuseError()
: Get error stateuseHasData()
: Check if data existsuseApiActions()
: Get all actions
- ESLint: Code linting
- Oxlint: Fast linting with Oxc
- Prettier: Code formatting
- TypeScript: Type checking
- Vite: Hot module replacement
- React DevTools: Component debugging
- Zustand DevTools: State debugging
# Run oxlint only
npm run lint:ox
# Run oxlint with auto-fix
npm run lint:ox:fix
# Run prettier formatting
npm run format
# Check prettier formatting
npm run format:check
# Run oxlint + prettier
npm run lint:format
# Complete linting pipeline (fix + format + check + build)
npm run lint:complete
npm run build
MIT