Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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 React-Rxjs:在流中转换父组件事件处理程序_Javascript_Reactjs_Rxjs - Fatal编程技术网

Javascript React-Rxjs:在流中转换父组件事件处理程序

Javascript React-Rxjs:在流中转换父组件事件处理程序,javascript,reactjs,rxjs,Javascript,Reactjs,Rxjs,给定父组件,将呈现以下内容: const handleButtonClick = (e) => { //code omitted } <ChildComponent handleButtonClick={handleButtonClick} /> 我还对如何在父对象呈现多个动态子对象的场景中实现这一点感兴趣,例如: return( <> { children.map((child, index) => { <C

给定父组件,将呈现以下内容:

const handleButtonClick = (e) => {
 //code omitted
}
<ChildComponent
 handleButtonClick={handleButtonClick} 
/>
我还对如何在父对象呈现多个动态子对象的场景中实现这一点感兴趣,例如:

return(
  <>
   {
     children.map((child, index) => {
        <ChildComponent handleButtonClick={handleButtonClick}/> 
     })
   }
  </>
)
返回(
{
children.map((child,index)=>{
})
}
)

fromEvent(button,“onClick”).pipe(filter(),mpa(),reduce()).subscribe()
如果在父组件中没有对该按钮的引用,您建议我如何将该按钮传递到
fromEvent
?是的,使用
Subject
看起来不错。在这种方法中有什么让你担心的吗?(这是一个类似的例子)@OlesSavluk我只是想知道是否还有另一种传统的方法,因为我是React初学者。首先,@cesartalves是对的,使用一个主题没有什么错。由于默认情况下它是多播的,所以它的开销(稍微)更大。以下是使用fromEvent的示例:
const clickStream = new Subject()

const handleButtonClick = (e) => {
 clickStream.next(e)
}
return(
  <>
   {
     children.map((child, index) => {
        <ChildComponent handleButtonClick={handleButtonClick}/> 
     })
   }
  </>
)