You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
useAtomCallback((get, set) => set(baseAtom, (v) => v + 1));
should behave the same, logically.
However, inside a ScopeProvider where only baseAtom is scoped, the former follows the scope rules and accesses the scoped baseAtom, while the latter accesses the global baseAtom. Interestingly, only write-only atoms seem to ignore the scope rules. If the first argument of someAtom is changed to (get) => null, the scope rules are respected.
The text was updated successfully, but these errors were encountered:
The current implementation of valued write atoms (aka write-only atoms) is to mutate the write function of the atom to intercept the getter and setter in order to resolve to nearest scoped atom. This was done to preserve the current value of the atom. Keep in mind that this value may not necessarily be null as custom write atoms can mutate themselves.
The issue with this implementation is that it only scopes the top-level valued write atom. useAtomCallback internally creates a valued write atom. Since only the baseAtom is scoped and not the write-only atom, incrementAtom1, the write chain loses scope. This is a bug.
To fix this, Jotai has recently implemented read and write traps. Implementing this new api should address this issue.
Reproduction example: https://codesandbox.io/p/sandbox/jotai-demo-forked-x6tmjn
and
should behave the same, logically.
However, inside a
ScopeProvider
where onlybaseAtom
is scoped, the former follows the scope rules and accesses the scopedbaseAtom
, while the latter accesses the globalbaseAtom
. Interestingly, only write-only atoms seem to ignore the scope rules. If the first argument ofsomeAtom
is changed to(get) => null
, the scope rules are respected.The text was updated successfully, but these errors were encountered: