I want to update the days value inside the state object each time and increate it’s value by one
const [leap, setLeap] = useState({state: false, days:0})
So i tried doing it like that but that did not help
setLeap((prevState)=> ({...prevState, days: days++ }))}
2
Answers
Destructure
days
out of the previous state, and assigndays + 1
to the newdays
state:You need to use the
days
key from the prevState for incrementing. Do as follows: