Configuring React Query
React Query is a great library for handling async data and making it available in React components.
Why React Query?
The main reason that React Query is a great option for handling the async remote state is the number of things it handles for us.
Imagine the following component, which loads some data from the API and displays it:
const loadData = () => Promise.resolve('data'); const DataComponent = () => { const [data, setData] = useState(); const [error, setError] = useState(); const [isLoading, setIsLoading] = useState(); useEffect(() => { setIsLoading(true); loadData() .then((data) => { setData(data); }) .catch((error) => { ...