Has anybody built a "indexed-by-ID" cache using react-query? #1257
Unanswered
subhan-nadeem
asked this question in
Q&A
Replies: 1 comment 4 replies
-
You can use initialData to read from another query https://react-query.tanstack.com/docs/guides/initial-query-data#initial-data-from-cache |
Beta Was this translation helpful? Give feedback.
4 replies
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.
-
I am using react-query for all of my data fetching logic in my react app. At a basic level, I have something like
useBooks(bookIds)
that uses react-query fetchesBook
objects based onbookIds
, like so:I want to implement the following functionality when calling
useBooks
:bookId
in the arraybookIds
already exists in a previously cached query, use that cachedBook
object rather than querying the server for itBooks
, keep adding them to this indexed-by-id cacheI'm wondering if anybody has figured out how to do this in a clean way? I've been thinking about coupling use of the react-query hook with a context provider but have not been able to flesh it out in its entirety yet.
Beta Was this translation helpful? Give feedback.
All reactions