DEV Community

Max
Max

Posted on

Answer: What do I have to do to update array values in the react hook?

react will not rerender if setState return the same state that was before when you use the push method you mutate the state object. instead create a new array with the new item.

always update your state in immutable way.

in your case:

onClick={() => {
   setArr((prevArr) => ([...prevArr, prevArr.length

Top comments (0)