Replies: 4 comments 2 replies
-
Could you make a simple reproduction of this logic in a codesandbox? I'm wrapping this PR up quickly and can test the new build against what you have there. I think what you have sounds reasonable. Currently, atomEffects have a microtask delay from when their atom dependency changed (e.g the atom was set), to when the effect runs. This PR removes that delay. But the effect's get and set are already both synchronous. I think you need the deferred promise because you are waiting for next signal, which is reasonable. So for next steps, let me see what you currently have in a codesandbox. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Here's what's going on.
To fix your issue, I recommending mounting atomEffect in a separate useAtomValue hook. |
Beta Was this translation helpful? Give feedback.
-
withAtomEffect is roughly equivalent to function withAtomEffect(effect: (get: Getter, set: Setter) => void) {
const countAtom = atom(0)
const effectAtom = atomEffect((get, set) => {
effect(get, set)
})
const countWithEffect = atom((get) => {
get(effectAtom)
return get(countAtom)
})
return countWithEffect
} |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions