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)