FormalinK
FormalinK
Najbardziej klimatyczna gra #pixelart w jaką graliście to..? #gry
- Yokoetneivvis
saveData = (collection, item) => {
if (item.id === "") {
item.id = this.idCounter++;
this.setState(state => state[collection]= state[collection].concat(item));
} else {
this.setState(state => state[collection]
= state[collection].map(stored =>
stored.id === item.id ? item: stored))
}
};
this.setState
powinno zwracać nowy obiekt, nie powinno się modyfikować stanu ręcznie. Spróbujthis.setState({
[collection]: [...this.state.collection, item]
});
this.setState({
[collection]: this.state[collection].map(stored => stored.id === item.id ? item : stored)
});
Wykop.pl