question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Option to push events into all atoms / or alternative

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
davidmccabecommented, May 14, 2020

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.

0reactions
RichardLindhoutcommented, Jun 3, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found