react hook copy previous array state code example
Example 1: usestate array push
setTheArray([...theArray, newElement]);
Example 2: prevstate in usestate
const [prevState, setState] = React.useState([]);
setState(prevState => [...prevState, 'somedata'] );