Skip to content

something confused me about Provider initialValues and scope #712

Closed Answered by dai-shi
chj-damon asked this question in Q&A
Discussion options

You must be logged in to vote

While it would be possible to raise a runtime error with a custom hook and a custom Provider, think it more like the atom config is an identifier or even a (global) variable.

Let's suppose you have a global variable in a big project and want to avoid directly accessing it, how would you? You wouldn't export the variable from the module. Likewise, you shouldn't export the atom config.


That said, there would be several (hacky) patterns to approach your needs. What I think is canonical for your use case is this:

const AtomNotInitialized = new Error() // or Symbol() or new Proxy(...) or just null
const atom1 = atom(AtomNotInitialized) // for module1
const atom2 = atom(AtomNotInitialized) // …

Replies: 16 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by chj-damon
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@dai-shi
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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

@chj-damon
Comment options

@chj-damon
Comment options

@Thisen
Comment options

Thisen Sep 16, 2021
Collaborator

@chj-damon
Comment options

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
Converted from issue

This discussion was converted from issue #711 on September 16, 2021 08:37.