what method used to update state in react js code example
Example 1: how to update react state array
const [myArray, setMyArray] = useState([1,2,3])
// to update
setMyArray([...myArray, 4]); // --> myArray = [1,2,3,4]
Example 2: how to update array in react state
this.setState(prevState => ({
arrayvar: [...prevState.arrayvar, newelement]
}))