DEV Community

Discussion on: Why you need to use React-Query in your React/React Native project

Collapse
 
ausmurp profile image
Austin Murphy

I want to start using this, or swr, but the examples I've seen continually show single calls, too simple. In a real web application, you will have multiple API calls for a page, somewhere. In NextJS maybe you're creating a page /account/123/users, and you need to fetch the account by id first, and then get the users for that account id after the account is fetched. Let's see something like this, a chained API example?

Collapse
 
benjamindaniel profile image
Benjamin Daniel

Hey, have you taken a look the rick and morty example, it does exactly what you are looking for, the Episode route handles that as it fetches the data for the episode with a unique id that depends on the episode's id, any subsequent load of that episode will only trigger silent refetch in the background, you can take a look at how the characters was prefetched for a more complex example. Does this help you?

Collapse
 
ausmurp profile image
Austin Murphy • Edited

Hey thanks! Following up, I converted our dashboard components to use react-query as they were the perfect candidates for it, and it is amazing. I still need to understand exactly how the keys work to refresh data when you pass an object as a key - assuming it's converted to a string under the hood. But it's working great.