[英]React state management between different components
So i have the following components structure : 所以我有以下组件结构:
1
/ \
2 4
| |
3 5
Component 3 is a marker displayed on a map. 组件3是在地图上显示的标记。 Component 5 is a list representing the markers on the map.
组件5是代表地图上标记的列表。
Will it be possible that once an onClick event happens on component 5 it will trigger some function/state in component 3 to open an infowindow? 一旦组件5发生onClick事件,是否有可能触发组件3中的某些功能/状态来打开信息窗口?
Yes, If you are using just React, then you can pass the click handle function from Root component (1) to component 5 and toggle the state for info window in there and pass the info window state all the way from Root component (1) to component (3). 是的,如果仅使用React,则可以将“单击句柄”功能从“根”组件(1)传递到组件5,并在其中切换信息窗口的状态,并从“根”组件(1)一直传递信息窗口的状态。到组件(3)。
Another way would be using Redux. 另一种方法是使用Redux。 Where you can dispatch a onclick action from component 5 to change the Redux store value and make the component 3 to connect to the redux store
您可以在其中调度组件5的onclick操作以更改Redux存储值,并使组件3连接到redux存储
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.