Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.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中更新父组件的父组件状态?_Javascript_Reactjs_Reactjs Flux - Fatal编程技术网

Javascript 如何在react中更新父组件的父组件状态?

Javascript 如何在react中更新父组件的父组件状态?,javascript,reactjs,reactjs-flux,Javascript,Reactjs,Reactjs Flux,我在玩fb的评论框教程。让我们想象一下,我已经添加了删除注释的功能,所以在注释组件中会有类似的内容- onClick={this.handleCommentDelete} 如何触发commentBox父组件状态的更改,而不在commentList组件中传播回调,然后传播到comment组件 <commentBox> <commentList> <comment> 我使用PubSub模式在组件之间进行通信。在评论框中: componentDidM

我在玩fb的评论框教程。让我们想象一下,我已经添加了删除注释的功能,所以在注释组件中会有类似的内容-

onClick={this.handleCommentDelete}
如何触发commentBox父组件状态的更改,而不在commentList组件中传播回调,然后传播到comment组件

<commentBox>
  <commentList>
    <comment>

我使用PubSub模式在组件之间进行通信。在评论框中:

componentDidMount: function() {
    PubSub.subscribe("COMMENT_DELETED", function( msg, data ){
        console.log( data ); //logs "commentId"
    });
}
在handleCommentDelete中:

PubSub.publish("COMMENT_DELETED", {commentId: commentId});

对于PubSub,我正在使用这个库,但当然还有其他库:。

Flux体系结构是实现这一点的一种方法。在此.handleCommentDelete中调用ActionCreators.deleteComment操作。调度员将其发送到所有门店。CommentStore通过删除注释对操作进行操作,并发出更改事件。正在侦听CommentStore的CommentBox会使用新的注释列表更新自身。这在一定程度上是一个什么组件实际拥有删除注释的行为的问题。它是基本级别的注释组件吗?或者某个容器?事件是通过父链传输状态的一种非常有效和非常清晰的方式,并建立了明确的所有者。然后你可以使用通量模式。。。