using spread operator in push array. react hooks code example
Example 1: React Hooks append state
setTheArray(currentArray => [...currentArray, newElement])
Example 2: usestate array push
setTheArray([...theArray, newElement]);
setTheArray(currentArray => [...currentArray, newElement])
setTheArray([...theArray, newElement]);