react array insert code example
Example 1: React Hooks append state
setTheArray(currentArray => [...currentArray, newElement])
Example 2: add new array at the back of react state
this.setState(prevState => ({
myArray: [...prevState.myArray, "new value"]
}))
Example 3: add items to a react array in hooks
const addMessage = (newMessage) => setMessages(state => [newMessage, ...state])