Dependent SWR hooks & Dependency Collection #2961
Unanswered
tjelvar-chromaway
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
TL;DR is a way for a custom hook that depends two SWR calls and have the last one take into account the response form the first one (except
data
andmutate
) without breaking dependency collection features, deduplication or caching?Consider this fictional scenario: I have a hook called
useGetBook()
however to get the book i need to call a async functiongetBooks
on anauthor
so i have to pass anauthorId
and abookId
.In the code example above i could read the
isLoading
fromauthor
and then return a newly constructed object that returnsisLoading: author.isLoading || book.isLoading
but then i would forcefully cause a re-render by accessingauthor.isLoading
. Another way i could see doing this is to move the async operations ofuseGetAuthor
intofetcher
but then i loose caching and deduplication.Beta Was this translation helpful? Give feedback.
All reactions