我无法将imageData添加到我的状态变量中
const fromLocalStorage = localStorage.getItem("test");
if (localStorage.getItem("test")) {
const dataFromLocalStorage = JSON.parse(fromLocalStorage);
let updatedData = data.map((d) => {
const result = dataFromLocalStorage.find( dfls => dfls.id === d.id );
return {...d, starIcon: result.starIcon} ;
})
this.setState({
data: updatedData
});
} else {
this.setState({ data: data.map(x => ({ ...x, starIcon: true })) });
}
答案 0 :(得分:1)
创建状态变量并将其添加为对象。
const updateField = e => {
setValues({
...autoData,
[imageData]: e.value
});
};
const [autoData, setValues] = useState({});