我可以通过传播操作符传递道具.即
<Component x={props.x} y={props.y} />
等于:
<Component {...props} />
我们可以在具有相同名称的组件定义中使用它.
<Component handleClick = {this.handleClick} anotherHandleClick = {this.anotherHandleClick}/>
编辑:
上面的行将传递函数handleClick和anotherHandleClick传递给子节点.是否有类似< Component {... Fns} />这样每个函数都会作为具有相同名称的道具传递下去.
是的,你可以这样做:
1)第一种方式:
render() { const methods = { handleClick : this.handleClick }; return( <Component {...methods} /> ) }
2)第二种方式:
不使用任何额外的varible const方法= {handleClick:this.handleClick};
render() { return( <Component {...this.constructor.prototype} /> // or <Component {...this.__proto__} /> ) }
NOTE : The second method is not preferable as it gives all the access@H_404_33@ of class to a child,all means all,constructor,render everything….
I just want to show the ways we can achieve,still if there are lots@H_404_33@ of functions we can go with second way too,but be careful with that.
以下是上述两个工作示例,请看一下: