raisiqueira / example-msw-vite

A real-world example of using MSW with Vite and @tanstack/react-query.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

example-msw-vite

A real-world example of using MSW with Vite and @tanstack/react-query.

Getting started

Clone the repository and install the dependencies:

git clone https://github.com/raisiqueira/example-msw-vite
cd example-msw-vite
pnpm install

Start the development server:

pnpm dev

Testing the project

Run the tests:

pnpm run test

Project structure

This project is based on the Eruption template.

This project is a simple example of a React application that uses MSW to mock API requests. All requests are mocked in the src/mocks/handlers.ts file.

To fetch data from the API, the application uses the @tanstack/react-query (former react-query).

The MSW files are located in the mocks folder. The src/mocks/browser.ts file is the entry point for the MSW worker. The src/mocks/handlers.ts file contains the handlers for the mocked requests.

The other related files are:

  • src/App/services: the file that contains an axios instance to fetch data from the API.
  • src/App/hooks: the file that contains the useQuery hook to fetch data from the API.
  • src/App/components/HLTVMatches: the file that contains the component that renders the fetched data.

License

MIT @ Raí Siqueira

About

A real-world example of using MSW with Vite and @tanstack/react-query.

License:Other


Languages

Language:TypeScript 49.5%Language:JavaScript 38.4%Language:CSS 9.6%Language:HTML 1.7%Language:Shell 0.7%