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.

[Question] How do I get the next state value?

See original GitHub issue
const [value, setValue] = useAtom(atom(1))

useEffect(() => {
  ...
  setValue(3)
  console.log(value) // === 1
  // how do I now get the latest value of the atom? 
})

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
dai-shicommented, Apr 3, 2021

That’s good to hear. Please note the use case of this util is not thoroughly tested / considered.

There is a hypothetical case it may not work as expected in Concurrent Mode in the future. (It’s a sort of edge case, if there’s a derived read atom (both sync and async), and if stateCallback is invoked before react updates the state in its scheduler, it would return an old value.) Technically impossible, but there might be a workaround on user end.

If anyone get an issue, please open a new issue. Closing this as resolved.

0reactions
dai-shicommented, Jun 21, 2021

Closing this as stale. We can reopen with a repro, or open a new one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to access the latest state value in the functional ...
React state updates are asynchronous, i.e. queued up for the next render, so the log is displaying the state value from the current...
Read more >
Introduction to State Table, State Diagram & State Equation
Digital Electronics: Introduction to State Table, State Diagram & State EquationContribute: http://www.nesoacademy.org/donateWebsite ...
Read more >
Solved Question 3 1 pts Enter the value of next state (Q+)
Question : Question 3 1 pts Enter the value of next state (Q+) when S=0, R =0 and present state (g)= 1 for...
Read more >
Why is the state-action value function used more than the state ...
1 Answer 1 · 2. It may be also worth emphasizing that, if you're using a table, the state-action value function will be...
Read more >
Hooks FAQ - React
This page answers some of the frequently asked questions about Hooks. Adoption Strategy. Which versions of React ... How to get the previous...
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