Skip to content

[Question] Updating atom from async loop #1723

Discussion options

You must be logged in to vote

useRecoilState (and all other hooks/fns where you can set state) accepts updater fn (state) => state where you get latest state with all the changes applied - not the state used in current render. Basically the interface and usage is the same as useState from react.

But I would reconsider the model of atoms and store the whole upload (promise) in an atom, so there's no isDone flag etc.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by artem-tarasenko
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1719 on April 08, 2022 21:21.