How can I remove an attribute from a Reactjs component's state object

后端 未结 10 2067
南笙
南笙 2020-12-06 09:17

If I have a react component that had a property set on it\'s state:

onClick() {
    this.setState({ foo: \'bar\' });
}

Is it possible to re

10条回答
  •  一个人的身影
    2020-12-06 09:47

    Use dot-prop-immutable

    import dotPropImmutable from "dot-prop-immutable";
    
    onClick() {
        this.setState(
           dotPropImmutable.delete(this.state, 'foo')
        );
    }
    

提交回复
热议问题