this.state.style:{ width: height: color } //修改属性 this.setState({style:{}})
Now I want to add an attribute to it through setState. Can I only add one attribute and keep the other attributes with their original values?
When using Object.assign(), be careful not to return the original object, but a new object:
Object.assign()
this.setState(Object.assign({}, this.state.style, {width: 666}))
When using
Object.assign()
, be careful not to return the original object, but a new object: