[英]Object assign on immediately created object when spread
I am a bit tired of passing react props this way 我有点厌倦了这样传递反应道具
<Comp one={one} two={two} three={three} />
So I started doing 所以我开始做
<Comp {...{one, two, three}} />
However I realized that this computes to Object assig 但是我意识到这可以计算为对象关联
react.createElement(Comp , Object.assign({
one: one,
two: two
}, {
__source: {
fileName: _jsxFileName,
lineNumber: 95
},
Since I'm spreading an object that I'm just creating I expected the compiler/transpiler to be smart enough to realize about that and do something like this instead 由于我正在散布一个我刚刚创建的对象,所以我希望编译器/编译器足够聪明,可以意识到这一点,并执行类似的操作
react.createElement(Comp ,{
one: one,
two: two,
__source: {
fileName: _jsxFileName,
lineNumber: 95
},
Is there any Babel plugin to accomplish this, or any way of compiling this way ? 是否有任何Babel插件可以完成此任务,或以这种方式进行编译的任何方式?
Regards 问候
The Babel version and settings you use are pretty important. 您使用的Babel版本和设置非常重要。
Using the latest, I had this code: 使用最新的代码,我得到了以下代码:
return (<Child {...{ name: this.name }} />);
Which turned into this: 变成了这样:
return Object(m.a)(t, e), Object(c.a)(t, [{
key: "render",
value: function() {
return o.a.createElement(k, {
name: this.name
})
}
}])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.