Global query store #750
Replies: 2 comments 2 replies
-
You are better to do the caching inside the fetcher rather than the resource creation. You can just return the cached value instead of the promise. Resources internally have an effect(more or less) that will get released (stop reacting) once the first component used this way gets unmounted. It would be more like React Query if each location made its own resource but read from the same cache. If you really wanted to share the resource you are probably better off using Context for this one. If the resource is first fetched in a parent your approach would be fine too, but something to be aware of. |
Beta Was this translation helpful? Give feedback.
-
Interested in a global query store solution, too. Implemented it with the caching inside the fetcher, as suggested. Any chance SolidJS will get some ready-to-use primitive for global queries sometime in the future? |
Beta Was this translation helpful? Give feedback.
-
Using
createResource
, and thanks to Solid architecture, I find it easy to create a global query store: a shared query resource, that is only fetched once, and used across multiple components without refetching on each component.I took the inspiration from
react-query
only without the revalidation (can be added usingrefetch
on specific conditions)Example below
Getting users
is logged only once.are there any caveats to this approach?
Beta Was this translation helpful? Give feedback.
All reactions