Skip to content

Scoped atom leaks to other Provider when storing Set #2760

Answered by rothsandro
lamualfa asked this question in Bug report
Discussion options

You must be logged in to vote

You define the initial value once when creating the atom and it is then reused for all providers / scoped because otherwise Jotai / Jotai Scope would have to clone your initial value (which isn't easy possible).

It should work if you use atomWithLazy because then you can create a new Set for every scope. You'll need to test it if everything works fine with Jotai Scope but I think it should.

const activeIdsAtom = atomWithLazy<Set<string>>(() => new Set([]));

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@lamualfa
Comment options

@rothsandro
Comment options

Answer selected by lamualfa
@lamualfa
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants