React Query is data fetching and caching library, it is best alternative for Redux store. The library uses hooks to fetch and store data.

Every hook returns data,isLoaing etc, an ideal hook call in a component look like.

export default function Home() {   const { data, isLoading } = useLocations(); .....

How about a second hook call in a same component ? There can't be second variable named data or isLoading.

Instead we can point data into another object by using the following syntax

export default function SignUp() {   const { data: locations, isLoading } = useLocations();   const { data: cities, isLoading:isLoading2 } = useCities();

Now we can replace the data variable with the locations and cities in the render section.


This free site is ad-supported. Learn more