ES6传播不会以这种方式工作
I have this.state = { sortedKey: null } in my constructor and I do
this.setState({
sortedKey: [...this.state.sortedKey, 'something']
})
我收到Cannot convert undefined or null to object
的错误?
答案 0 :(得分:1)
var state = { "sortedKey": [] };
var newState = {"sortedKey": [...state.sortedKey, 'something']};
console.log(newState)