Fetching for each data in collection
See original GitHub issueWhen you have a dependent call and you want to make a call for each of the data in the collection, how does you handle that with swr?
const { data: users } = useSWR<Response<User[]>>(
[usersURL(), token],
request,
{ revalidateOnFocus: false },
);
const allProfiles = [];
if (users) {
users .data.forEach(user => {
const { data: profiles } = useSWR<Response<Profile[]>>(
[userProfileURL(user.id), token],
request,
{ revalidateOnFocus: false },
);
if (profiles) {
allProfiles.push(profiles);
}
});
}
The above code snippet does not work, I am getting errors like this Rendered fewer hooks than expected.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Retrieving Elements from Collection in Java (For-each, Iterator ...
Cursor is an interface and it is used to retrieve data from collection object, one by one. Cursor has 3 types, which are...
Read more >Fetching for each data in collection #156 - vercel/swr - GitHub
When you have a dependent call and you want to make a call for each of the data in the collection, how does...
Read more >Fetch documents from collection in MongoDB - w3resource
Fetch all data from the collection ... If we want to fetch all documents from the collection the following mongodb command can be...
Read more >MongoDB Show all contents from all collections - Stack Overflow
To show all collections content or data use below listed code which had been posted by Bruno_Ferreira. var collections = db.getCollectionNames(); for(var i ......
Read more >Fetch all data from two different collection using single query
Hello… can you help me with a query that can fetch all data from two different collections in a single query. consider example:...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks like this has been solved!
For future reference, the error
Is caused by using hooks under a conditional:
Additionally, you can do dependent fetching as described here: https://github.com/zeit/swr#dependent-fetching
@sergiodxa this is the solution I went for!
Then use the
fetchSomething
like this: