Skip to content

Is it a good idea to create a weakmap atom? #2991

Answered by dmaskasky
codenoobforreal asked this question in Q&A
Discussion options

You must be logged in to vote

If you want to have separate weakmaps per store, you should do:

atom(() => new WeakMap())

This notation will ensure that the weakmap isn't the same across all stores.


I'm not sure of the benefit of putting a weakmap in an atom (unless you want unique weakmaps for each store). Since the reference to the weakmap never changes, you don't really need reactivity. A global weakmap should be sufficient.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@codenoobforreal
Comment options

Answer selected by codenoobforreal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants