React Hooks Добавить состояние
setTheArray(currentArray => [...currentArray, newElement])
Jeff Le
setTheArray(currentArray => [...currentArray, newElement])
setMyArray(oldArray => [...oldArray, newElement]);
const addMessage = (newMessage) => setMessages(state => [...state, newMessage])
setTheArray([...theArray, newElement]);