- Since React is a UI library, there is not specific pattern for data fetching
- useEffect hook for data fetching and useState hook to maintain component state like loading, error or resulting data.
- If the data is needed throughtout the app, we tend to use state management libraries.card
- Most of the state managatment libraries are good for working with client state. Ex: 'theme' for the application/ whether a modal is open.
- State management libraires are not great for working with asynchronous or server state.em>
- Persisted in your app memory and accessing or updating it is synchronous.
- Persisted remotely and requires asynchronous APIs for fetching or updating.
- Has shared ownership.
- Data can be updated by someone else without your knowledge.
- UI data may not be in sync with the remote data.
- Challenging when you have to deal without caching, deduping multiple requests for the same data, updating stale data in the background, performance optimizations etc.
- Basic queries
- Poll data
- RQ dev tools
- Create reusable query hooks
- Query by ID
- Parallel queries
- Dynamic queries
- Dependednt queries
- Infinite & paginated queries
- Update data using mutations
- Invalidate queries
- Optimistic updates
- Axios Interceptor