Within an Atom Effect - the onSet() listener is fired on every access with the trigger being either 'set' or 'get'.
Since this listener function is called every access, both on set and on get - would it be better to name it onAccess or listener similar?
Cheers B
The onSet() listener is only called when the atom value is changed. The atom effect function itself is called when the atom is initialized on first use, which may be either due to a set or a get.
@drarmstr
Apologies for continued questions here - but in the case that an atom is used, then reset - either using useResetRecoilState(state) or resetSelf() - would subsequent usage of this atom be considered 'first use' and would the effect function run?
@drarmstr
Apologies for continued questions here - but in the case that an atom is used, then reset - either using
useResetRecoilState(state)orresetSelf()- would subsequent usage of this atom be considered 'first use' and would the effect function run?
It's not guaranteed. If you reset an atom or if no one is subscribing to an atom, then they are candidates to be released and can be cleaned up, though they may not be. If that happens, then subsequent usage would re-initialize the atom and call the effect function again. This is similar to a React effect for a component. So, for both cases, it is important to carefully return a cleanup handler and be ready to handle the effect being called multiple times.
Added documentation with #680