Open sarobolket opened 2 years ago
I had the same problem, and it turned out that it was the combination of React 18 and strict mode. Inside an internal Recoil component called RecoilRoot_INTERNAL there is an useEffect() that initializes and cleans up the internal state store When Recoil runs in strict mode that effect is called multiple times and during all this reinitialization all effect subscriptions generated when calling onSet are removed. So the workaround was to bail out of strict mode.
I want to update an atom with the query string in the URL. With useSetRecoilState I can set the atom but recoil-persist doesn't save in localStorage. I can see that the onSet callback in the effects of the atom is not triggered.
See this example:
How can I solve it? Some example with recoil-sync??