React Query is data fetching and caching library, it is best alternative for Redux store. The library uses hooks to fetch and store data.
As we know, a react-query share data like a global state so that we can update all the components using the query hook.
How do we manually re-fetch query ?
The process is called invalidation , this can be done with Query client object and unique query key.
import { QueryClient, } from "react-query"; ..... queryClient.invalidateQueries("categories");
The categories query will invalidate and re-fetch the data , so the all the components using it will have new state of data.
I personally prefer react-query over Redux-toolkit, it is fast, performant and easy to configure.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.