Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将eventhandler传递给同级组件?_Javascript_Reactjs - Fatal编程技术网

Javascript 如何将eventhandler传递给同级组件?

Javascript 如何将eventhandler传递给同级组件?,javascript,reactjs,Javascript,Reactjs,我有一个eventHandler,我希望它的同级组件来处理它。中有许多属性(例如构造函数中的this.randomNumber=555)是处理事件所需的onleftmove render( ) { <div> <LeftControl onTouchMove={this.onLeftMove} /> <Brains ..wants to handle onLeftMove because onLeftMove needs access to a

我有一个eventHandler,我希望它的同级组件来处理它。
中有许多属性(例如构造函数中的
this.randomNumber=555
)是处理事件所需的
onleftmove

render( ) {
  <div>
    <LeftControl onTouchMove={this.onLeftMove} />
    <Brains ..wants to handle onLeftMove because onLeftMove needs access to a lot of properties inside Brains.. />
  </div>
}
render(){
}

如何做到这一点?

您需要这样做。这意味着共同祖先——呈现
LeftControl
Brains
的祖先——将保存它们都需要的所有信息。

您需要这样做。这意味着共同祖先——呈现
LeftControl
Brains
的祖先——将保存这两者所需的所有信息。

在这种特定情况下,我无法提升状态的可能副本。@J.Reku为什么不?在这种特殊情况下,你通常无法提升状态。@J.Reku为什么不能?你通常可以