score:2

Accepted answer
onClick={() => {
   setArr((prevArr) => ([...prevArr, prevArr.length + 1]));
}}

score:0

const [userInput, setUserInput] = useState({
        enteredTitle: '',
        enteredAmount: '',
        enteredDate: ''
    });
setUserInput((prevUserInput)=>{
          return {
            ...prevUserInput,
            enteredTitle: "Something Else"
        }
})
//for copying the whole object, and only changing enteredTitle's value in it

score:1

const [arr, setArr] = useState([1,2,3])
setArr([...arr,1])

Related Query

More Query from same tag