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
dataandmutate) 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 functiongetBookson anauthorso i have to pass anauthorIdand abookId.In the code example above i could read the
isLoadingfromauthorand then return a newly constructed object that returnsisLoading: author.isLoading || book.isLoadingbut then i would forcefully cause a re-render by accessingauthor.isLoading. Another way i could see doing this is to move the async operations ofuseGetAuthorintofetcherbut then i loose caching and deduplication.Beta Was this translation helpful? Give feedback.
All reactions