This project demonstrates how to use React Query (TanStack Query) for data fetching and state management in a React application, integrated with an AdonisJS backend API.
adonis-api-backend/- Backend API built with AdonisJSreact-query-example/- Frontend React application using React Query
- Node.js (v18 or higher)
- npm or yarn
-
Navigate to the backend directory:
cd adonis-api-backend -
Install dependencies:
npm install
-
Set up the database (if required) and run migrations:
node ace migration:run
-
Start the development server:
npm run dev
The backend will be running on http://localhost:3333 (default AdonisJS port).
-
Navigate to the frontend directory:
cd react-query-example -
Install dependencies:
npm install
-
Install React Query:
npm install @tanstack/react-query
-
Start the development server:
npm run dev
The frontend will be running on http://localhost:5173 (default Vite port).
- React Query for efficient data fetching and caching
- Tailwind CSS for styling (font sizes:
text-smfor headings,text-xsfor paragraphs,text-basefor main headings) - TypeScript support
- ESLint for code linting
- Vite for fast development builds
- Start both the backend and frontend servers as described above.
- Open your browser and navigate to
http://localhost:5173. - The React app will demonstrate various React Query features like:
- Fetching data
- Caching
- Mutations
- Error handling
- Loading states
The backend provides the following endpoints (example):
GET /api/posts- Fetch all postsPOST /api/posts- Create a new postPUT /api/posts/:id- Update a postDELETE /api/posts/:id- Delete a post
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
This project is licensed under the MIT License.