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.

useRecoilCallback batched set calls update state incorrectly

See original GitHub issue

We’ve been using Recoil quite extensively and believe we have encountered a bug with useRecoilCallback and state updating.

There is a rootState atom that we want to update via a useRecoilCallback that contains multiple set calls. If the set calls within useRecoilCallback try to set the recoil state of rootState directly or through a single selector layer, the final rootState is as expected. However, if there is more than one layer of selector dependencies, it is only the last set that has a result on rootState.

Here is the CodeSandbox.

Expected: All steps change their state from ['1', '2', '3'] to ['one', 'two', 'three'] Result: The only step changing the state is the last one for which set has run. In effect: ['1', '2', '3'] changes to ['1', '2', 'three']

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
drarmstrcommented, Oct 6, 2022

@luishdz1010 - I see the issue, though it does seem like a different one than the OP.

1reaction
dashkin-dimacommented, Aug 11, 2022

Сould I work on this problem?

Read more comments on GitHub >

github_iconTop Results From Across the Web

useRecoilCallback(callback, deps) | Recoil
This hook can be used to construct a callback that has access to a read-only Snapshot of Recoil state and the ability to...
Read more >
Recoil State is not updating properly - reactjs - Stack Overflow
It turned out it's actually a react problem. The setValues is updating the value but the updated value can only be accessed on...
Read more >
Recoil – A state management library for React | Hacker News
Sagas are put together with bailing twine and rely too much on generators for my taste. (The source code is smart but it's...
Read more >
Recoil: State Management for Today's React - YouTube
We present an approach to state management that scales from a single component to highly complex apps. This boilerplate-free system makes it ...
Read more >
How to Manage Your React Application State With Recoil.js ...
Whenever that atom changes, components calling the useRecoilValue or ... you to pass parameters to the get and set callbacks of a selector....
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