This project demonstrates the basic usage of react-query
for data-fetching in a React application. It uses json-server
and graphql server as a mock api backend.
To install the required dependencies:
npm install
To start the project:
npm start
The database structure for the mock server is found in db.json
:
The rest api server runs on port 5000
.
The graphql api runs on port 5001
.
-
App.js: This component fetches and displays posts using the
useQuery
hook fromreact-query
.- It handles different states like loading, error, and success.
-
index.js: The entry point of the app. It wraps the application within the
QueryClientProvider
to providereact-query
functionalities to the child components.
start
: Runs React, RestAPI and GraphQL serversserver
: Starts thejson-server
using thedb.json
file.