Option to push events into all atoms / or alternative
See original GitHub issueI’m rewriting my app from redux to recoil, it’s going great, but I did have a global ‘RESET’ action for example when I logout. I want some reducers to reset themselves. I think I can fix this with more explicit approach of using useResetRecoilState() in my logout button but I was wondering if you did have an alternative for that use-case.
import { atom } from 'recoil'
export const answeredFlows = atom({
key: 'answeredFlows',
default: [],
globalEvents: (event: { type: string }) => {
if (event.type === 'LOGOUT') {
return []
}
},
})
I guess you don’t want to recreate Redux but sometimes it would be cool to pass an event to all atoms.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Pushing Events: with and without JS.push - Fly.io
On its own, JS.push provides a combined API for pushing events to the server, specifying targets and payloads, and customizing loading states.
Read more >Question: The theory says that I must use a local atom if I must ...
If that's the case, an alternative solution is Boomi API management in combination with a local Atom. There's no need for a Cloud...
Read more >Push Options - GitLab Docs
GitLab supports using client-side Git push options to perform various actions at the same time as pushing changes. Additionally, Push Rules offer ...
Read more >Simple Event Driven Microservices with Spring Cloud Stream
Step 2: Choose Between Kafka or RabbitMQ Mode. In steps 3 & 4 which follow, we must substitute the -P<profile-choice> with the name...
Read more >What Is An Atom ? | NRC.gov
Likewise, just as when you experience resistance trying to push the same ends of two ... The number of protons in the nucleus,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for your interest Richard!
As you mentioned, you can delete the value of an atom using
useResetRecoilState
.If you want a reducer-style interface to atoms, you can create a hook that exposes such an interface and export that from the module instead of the atom itself.
Yeah I did have the same use case so I did create https://github.com/web-ridge/react-ridge-state since I don’t have the use-case for recoil yet and needed my state globally too