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.

Atom effect able to get another atom's value

See original GitHub issue

I’ve been looking into atom effects and they look really helpful. In the example, it shows a state synchronization example effect like this:

const syncStorageEffect = userID => ({setSelf, trigger}) => {
  // Subscribe to remote storage changes and update the atom value
  myRemoteStorage.onChange(userID, userInfo => {
    setSelf(userInfo); // Call asynchronously to change value
  });

  // Cleanup remote storage subscription
  return () => {
    myRemoteStorage.onChange(userID, null);
  };
};

That looks perfect, if myRemoteStorage is a static, but how would you structure that same effect when myRemoteStorage is coming from a Recoil value? If the datastore is also tracked in a Recoil atom, then I can’t figure out a good pattern for using it in an effect. Was there an approach in mind to handle that pattern?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:18
  • Comments:20 (5 by maintainers)

github_iconTop GitHub Comments

42reactions
drarmstrcommented, Nov 5, 2020

@mdlavin - We are exploring the ability for atom effects to look at the state of other atoms, perhaps via providing a mechanism like getSnapshot() as a callback for the atom effect.

5reactions
dsboocommented, Jun 19, 2021

also i think it’s a good feature if it possible that in effects_UNSTABLE.onset, update other atom. i want some atom’s effect propagation to other atom’s effect.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Atom Effects | Recoil
Atom effects are an API for managing side-effects and synchronizing or initializing Recoil atoms. They have a variety of useful applications such as...
Read more >
Can I change other pieces of state in a Recoil Atom Effect
I have several Atoms: An atom which stores an authentication token, for use when communicating with the storage API. Atoms for various pieces...
Read more >
Electron Affinity - Chemistry LibreTexts
As the name suggests, electron affinity is the ability of an atom to accept an electron.
Read more >
Mastering Periodic Trends
pairs orient themselves as far away as possible from each other, causing the electron cloud to expand (justifies trends across a period). 1....
Read more >
Electronegativity - Definition, Periodic Trends, Effect ... - Byju's
Factors Affecting Electronegativity · 1. Size of an Atom: A greater atomic size will result in less value of electronegativity, this happens because...
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