Modeling firebase subscriptions with selectors #1863
-
Hi, I'm currently using atom effects to model firebase subscriptions. To simplify the question, is there something like setSelf of atom effects in selectors to asynchronously update the selector. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
There isn't any callback to change the value once the evaluation has completed and been cached. But, the setSelf() in the atom effect can be called asynchronously. So, you could subscribe to your user preference change in the Atom effect and then call setSelf(). Alternatively, you could use useRecoilCallback() to create a callback used when your preference changes to update the atom value. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick response. By "you could subscribe to your user preference change in the Atom effect " do you mean using some mechanism in the recoil API or externally. Currently there is a settings atom that I use "getLoadable" to read in the atom effect before setting up the firebase subscription. My understanding was that getLoadable is a one time read and not a subscription. Is there a way to subscribe to other atoms/selectors from within atom effects? Thanks |
Beta Was this translation helpful? Give feedback.
-
Yeah, I mean subscribing using whatever mechanism Firebase uses within the atom effect. There is no way to subscribe to other atoms/selectors from an effect, though. If you want to subscribe an effect to multiple atoms/selectors you can always use |
Beta Was this translation helpful? Give feedback.
Yeah, I mean subscribing using whatever mechanism Firebase uses within the atom effect. There is no way to subscribe to other atoms/selectors from an effect, though. If you want to subscribe an effect to multiple atoms/selectors you can always use
useEffect()
. That, coupled withuseRecoilCallback()
can enable you to subscribe to everything and update multiple atoms.