加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 16:16:00 所属栏目:百科 来源:网络整理
导读:这是我的反应原生代码: NavigatorIOSref='nav'style={styles.container}initialRoute={{ title: 'List',component: TaskList,rightButtonTitle: 'new',onRightButtonPress: () = { this.refs.nav.push({ title: 'Add Task',component: AddTask }); }}} / 如
这是我的反应原生代码:

<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的源代码.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读