append to array usestate code example
Example 1: React Hooks append state
setTheArray(currentArray => [...currentArray, newElement])
Example 2: add items to a react array in hooks
const addMessage = (newMessage) => setMessages(state => [...state, newMessage])
Example 3: add items to a react array in hooks
const addMessage = (newMessage) => setMessages(state => [newMessage, ...state])