Ich habe die folgende Funktion:Warum werden Schlüsselwertpaare zweimal zum Status hinzugefügt?
handleAddItem(s) {
var key = Object.keys(s)[0];
var value = s[key];
var allItems = {...this.state.items};
allItems[key] = allItems[key];
allItems[key].push({name: value});
var ourItems = {};
ourItems = allItems[key];
ourItems.push({name: value });
this.setState({items: allItems});
}
Ich weiß, dass ourItems ist alles nicht wirklich wohl zu tun, aber warum, wenn diese drei Zeilen zweimal angeben hinzugefügt werden, um die Schlüssel-Wert-Paare hinzugefügt?
können Sie diesen Zustand einstellen? – DCR