This project utilizes React Query (TanStack Query) for efficient server state management. Here is a breakdown of the key concepts implemented:
- Client Provider: The application is wrapped in a
QueryClientProvider, which makes theQueryClientavailable to all components. - Fetching Data: We use the
useQueryhook to fetch data from our API endpoints. This hook handles caching, background updates, and stale data management automatically. - Mutations: For creating, updating, or deleting data, we use the
useMutationhook. This allows us to perform side effects and then invalidate queries to refresh the UI with the latest data. - DevTools: The
ReactQueryDevtoolscomponent is included to visualize the state of queries during development.
- Automatic Caching: Data is cached by unique query keys.
- Background Refetching: Data is kept fresh by refetching when the window is refocused or the network reconnects.
- Loading & Error States: Built-in
isLoadingandisErrorflags simplify UI rendering logic.