is it right or wrong please help
This is my functional component code
setaddCategories((prevState) => {
return [...prevState, { category_name: "", expense_categories_id: 0 }];
});
and here I turn it into class component
this.setState({
addCategories: (prevState) => {
return [...prevState, { category_name: "", expense_categories_id: 0 }];
},
});
This is the way to get this (Updated)
this.setState(prevState => ({
addCategories: {
...prevState.addCategories,
category_name: "",
expense_categories_id: 0
}
}));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.