【发布时间】:2019-12-23 06:24:26
【问题描述】:
在 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),
}
只是好奇有没有办法做到这一点。
【问题讨论】:
-
我在某处看到了支持
{ this.state.thing, ... }的提案,但是我找不到了,所以似乎不会指定。 -
@JonasWilms github.com/rbuckton/…
标签: javascript reactjs ecmascript-6