-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Learn React Hooks - Second Edition
By :
In the previous section, we used an Effect Hook to trigger the request, and a Reducer Hook to update the state, using the result from the request. Instead of manually implementing requests like this, we can instead use the TanStack Query library. This library not only allows us to easily fetch resources, but also caches the result for us and provides ways to invalidate the state. Invalidation allows us to, for example, re-fetch posts from the server after creating a new post, instead of having to manually dispatch an action.
Before we can get started using it, we need to install and set up the library. TanStack Query is a library used to manage state of server data. It consists of 3 parts: