Conceptual issue with atomFamily and atomWithDefault #2779
Unanswered
stickfigure
asked this question in
Q&A
Replies: 1 comment 2 replies
-
atomFamily is lazy by default, and the async atoms that it returns for your case will suspend the consuming React components until they load. I think these defaults are intuitive and sensible. But if you are looking to preload / hydrate these things and you know which store you want to use, you could do something like: thingIds.map(thingFamily).forEach(store.get) This will initiate the fetch for these things. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi - I'm pretty new to Jotai, and struggling with something that seems like it should be super obvious.
This seems like a pattern that can be found in nearly every web application:
/things
)/things/123
)Ideally:
/things
to/things/123
shouldn't need to load anything from the server (we already have that state!)/things/123
(or reloading that url) should load Thing123's state (we didn't start by loading all things)It feels like there's some combination of
atomFamily
andatomWithDefault
that should accomplish this but I'm struggling to figure out the right pattern. Is there a simple example anywhere?Taking a stab at it, I end up with something like:
...which handles the
GET /things/123
case. But how do I create an atom for theGET /things
case that pre-populates the family atoms? I am confused.Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions