在 React 项目中,我想通过在特定时间记录状态的特定部分来快速解决问题。
console.error('this.state.thing', this.state.thing);
这样做,我的 ESLint 配置给了我错误“必须使用解构状态分配”。所以,我要么关闭这个 ESLint 规则,要么我必须这样做:
const { thing } = this.state;
console.error('this.state.thing', thing);
这很好,但它让我想知道我是否可以一次性在对象文字中以相同的方式解构一个属性:
const objectLiteral = {
thing: this.state.thing, // how to destructure thing out of state?
stuff1,
stuff2: otherData,
};
const somethingLikeThis = {
thing: ({ thing } = this.state),
}
只是好奇是否有办法做到这一点。