Building parallel queries
A typical pattern that we often find the need to use is parallel queries. Parallel queries are queries that are executed at the same time to avoid having sequential network requests, often called network waterfalls.
Parallel queries help you avoid network waterfalls by firing all the requests simultaneously.
React Query allows us to perform parallel queries in two ways:
- Manually
- Dynamically
Manual parallel queries
This would probably be how you would do parallel queries if I asked you to do it right now. It involves just writing any number of useQuery
hooks side by side.
This pattern is great when you have a fixed number of parallel queries you want to execute. This means that the number of queries you will perform will always be the same and not change.
This is how you can write parallel queries following this method:
const ExampleOne = () => { const { data: queryOneData } = useQuery({ ...