array add element in array in hooks onclick code example
Example 1: add items to a react array in hooks
const addMessage = (newMessage) => setMessages(state => [...state, newMessage])
Example 2: add items to a react array in hooks
const addMessage = (newMessage) => setMessages(state => [newMessage, ...state])