Skip to content

Controlling when state is loaded, load only on sub-routes #2644

Answered by dai-shi
ysageev asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for opening up a discussion.

Your confusion is understandable. I think it would be nice to establish a certain pattern and it in docs.
So, as you know, a Jotai store is just like a WeakMap, and Provider is just to separate a store.
This means Jotai "core" is designed only for "global" store.

To use it "contextual", I think there are some options:

  1. use React Context to pass down an atom.
  2. use React Context to pass down the current route.
  3. use an atom that tracks the current route (or use atom-in-atom pattern). (This isn't truly contextual.)
  4. use jotai-scope

I wonder if anyone else has some experience with it.

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@dai-shi
Comment options

@ysageev
Comment options

@dai-shi
Comment options

Answer selected by ysageev
Comment options

You must be logged in to vote
2 replies
@ysageev
Comment options

@iwoplaza
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants