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.

[Feature request] selector support for useRecoilTransaction()

See original GitHub issue

I have the following issue.

Let’s say I have atom A with value 1.

  1. In mouse event handler the recoil callback with setter is called to set A value to 2.
  2. setTimeout callback fires, which in turn contains the recoil callback call. the snapshot in it still contains the A value of 1. The result of first step is not yet applied.

My question. Can I force all of the updates of the recoil callback to be applied right after the callback exits. e.g explicitly force not to batch it into a single transaction with subsequent callback calls ?

So subsequent callback (step two described above) call can read back the written value of previous callback call.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
cneurocommented, Nov 3, 2022

This is definitely a feature I am missing in Recoil right now. A large application will likely have the requirement to get and set various atoms and selectors in one reusable “transaction” (akin to a traditional reducer), and currently I’ve come across only really one way to achieve this, which is via vanilla React hooks. There are several problems using traditional hooks in this way:

  1. There is a lot of boilerplate involved in initializing all the values and setters of the atoms and selectors
  2. The hook always needs to return a function that does the setting, which requires wrapping it in a useCallback with all its dependencies (lots of boilerplate again)
  3. The only way to get close to the functionality as suggested by useRecoilTransaction is a selector with a setter that does all the work. However, it needs an arbitrary getter which results in confusing and ugly patterns.

It’s entirely possible I am going about this wrong of course - anyone else have a solution akin to useRecoilTransaction but with selectors?

I’d also like to echo @yoavniran and others here from over a year ago; is there a roadmap to move Recoil transactions from UNSTABLE to a permanent feature including the use of selectors? Thanks to @drarmstr and the dev team for all your efforts!

EDIT: typos & grammar

0reactions
yoavnirancommented, Sep 8, 2021

Am I right to think that useRecoilTransaction would/should be the only way to write setters with multiple “set” calls? If so, its really missing the option to get from selectors (and not just atoms). Is there a release date we can expect this to become available? thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

useRecoilTransaction_UNSTABLE(callback, deps) | Recoil
Dynamically updating an atom where we may not know at render-time which atom or selector we will want to update, so we can't...
Read more >
Exploring Asynchronous Requests in Recoil - AppSignal Blog
In this post, I'll take a close look at asynchronous queries in Recoil. I'll show you what the library is capable of and...
Read more >
Getting Started with React Recoil | by kelly woo - Bits and Pieces
deep dive in atom & selector of recoil.js. ... with selectors are a bit tricky, I didn't write it here but selector supports...
Read more >
Is it possible to initialise atomFamily multiple values at once?
In the meantime, is the useRecoilTransaction() approach more performant for you ... Feature Request: Add support for npm pakages, 0, 2022-03-21, 2022-10-29.
Read more >
pm
The take_snapshot() function creates a snapshot instance. 5. ... The API package defines the Java interfaces supported by the Asset Consumer OMAS.
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