amitmerchant1990 / amitmerchant-dot-com-comments

1 stars 0 forks source link

using-value-of-state-variables-after-updating-in-react/ #98

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Using value of state variables right after updating in React.js — Amit Merchant — A blog on PHP, JavaScript, and more

Working on one of the apps which built on top of React.js, I stumbled upon a scenario where I needed to use the value of a state variable immediately after it’s updated.

https://www.amitmerchant.com/using-value-of-state-variables-after-updating-in-react/

Ryan-Zayne commented 1 year ago

The preferred solution here would be simply to store the next state in a local variable and pass that into both the setter function and the moveNext function.

You can read the new react docs on getting rid of useless effects like this to better understand what I mean

Ryan-Zayne commented 1 year ago

Loving the site design btw👌