React 文档说Never mutate this.state directly, as calling setState() afterwards may replace the mutation you made. Treat this.state as if it were immutable...
但是当我根本不使用 setState() 时,这不是问题。
我能想到的唯一缺点是:
无法使用
shouldComponentUpdate
/componentWillUpdate
/componentDidUpdate
比较新旧状态。可能会使其他工作人员的可维护性变得更加困难。因为这不是做事的标准方式。
但是不使用 setState() 和直接改变 state是否还有其他缺点?
编辑:我已经删除了我被这个想法所吸引的理由。我知道这是一种反模式,我知道这可能不是最好的方法。但这个问题完全是关于“为什么”。
EDIT2:另外这里的关键词是other
在... are there any other disadvantages ...