0

is there any promise about order of useState setters, lets say my code looks like this:

const [one,setOne]=useState(0)
const [two,setTwo]=useState(0)

and lets say theres a handler or a useEffect with the 2 consecutive lines:

setOne(1)
setTwo(1)

is there a guarantee on which setter runs first? I'm asking since its not the same as asynchronous function followed by synchronous function

Tushar Shahi
  • 16,452
  • 1
  • 18
  • 39
ihab
  • 1
  • 1
  • Does this answer your question? [Does React keep the order for state updates?](https://stackoverflow.com/questions/48563650/does-react-keep-the-order-for-state-updates) – Tushar Shahi Oct 01 '22 at 11:54
  • React state update when component re render. For your question both state will be updated when component re render – kennarddh Oct 01 '22 at 12:15

1 Answers1

1

React does batching of all state updates at once so order does not really matter...if there are consecutive state updates then React will update in a single render. useEffect run in the order in which they are defined.