javascript - ECMA6 spread parameters in react-router -
i see reactjs sample code written as,
var app = react.createclass({ render: function () { return ( <div> <div classname='content'> <routehandler {...this.state} /> </div> </div> ) } })
this part confuses me.
<routehandler {...this.state} />
in this, routehandler
custom element uses ...
. , ecma6 functions splat/rest params use triple dots in function definitions. so, why people use ...
during function invocation (or) on application side?
this not rest operator spread operator, applied jsx attributes. see jsx spread attributes.
<routehandler {...this.state} />
equivalent react.createelement(routehandler, object.assign({}, this.state))
.
note object spread , rest operators jsx spread attributes feature inspired not part of es6 specification. there a stage 1 proposal include them in es7. in meantime, can use them passing --harmony
option jsx compiler cli, or --stage 1
option babel cli.
Comments
Post a Comment