当前位置 : 主页 > 网页制作 > React >

react-native – 在React Native中的组件之间进行通信?

来源:互联网 收集:自由互联 发布时间:2021-06-15
这是我的反应原生代码: NavigatorIOSref='nav'style={styles.container}initialRoute={{ title: 'List', component: TaskList, rightButtonTitle: 'new', onRightButtonPress: () = { this.refs.nav.push({ title: 'Add Task', component: AddTas
这是我的反应原生代码:

<NavigatorIOS
ref='nav'
style={styles.container}
initialRoute={{
    title: 'List',
    component: TaskList,
    rightButtonTitle: 'new',
    onRightButtonPress: () => {
        this.refs.nav.push({ 
        title: 'Add Task',
        component: AddTask
        });
    }
}} />

如何将一些通知从AddTask组件推送到TaskList组件?

文档说:“对于没有父子关系的两个组件之间的通信,您可以设置自己的全局事件系统.”

所以我需要建立一个全球事件系统?

像 communicate-between-components说:

For communication between two components that don’t have a
parent-child relationship, 07001 pattern is one of the possible
ways to arrange this.

您可以在react-native项目中使用Flux.

这是Flux React-Native的演示:

您可以查看github的源代码.

网友评论