I have this problem. I try to update mi object with useState but doesn't work. Below i paste the real case. I use React 18.2.0
const [filter, setFilter] = useState({year: 0, month: 0});
const buttonClick = (data) => {
// Jenuary 1st 2022
let datObj = {
year: 2022,
month: 1
}
setFilter((obj) => { return {...obj, ...{year: datObj.year, month: datObj.month} }});
console.log(filter);
//
// print always {year: 0, month: 0}
I Try many many times...but i suppose I'm wrong...or i don't understand..Can you help me? Thanks.