react hooks push to array if code example
Example 1: usestate array push
setTheArray([...theArray, newElement]);
Example 2: add items to a react array in hooks
const addMessage = (newMessage) => setMessages(state => [newMessage, ...state])
setTheArray([...theArray, newElement]);
const addMessage = (newMessage) => setMessages(state => [newMessage, ...state])