1

If you create a state like;

const [count, setCount] = useState(0);

and increment it with different methods. Result varias depends on the way I increment.

setCount(count + 1) //this returns the correct value.

setCount(++count) //this does not return the correct value.

Olgun Kaya
  • 2,426
  • 4
  • 30
  • 43

1 Answers1

1

You shouldn't directly mutate the state value,

setCount(++count)

see this post Why can't I directly modify a component's state, really?

aeXuser264
  • 2,755
  • 4
  • 13
  • 29