react-native - 我想以原生反应将数据发送到子屏幕我添加了代码
问题描述
我想将数据发送到子屏幕。这是我的代码。我想将数据发送到 allchilddtata。
<View>
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen name={COURSE_INTRODUCTION} component={Adddata} exampledata={example} />
<Tab.Screen name={COURSE_VIDEO} component={LessonVideo} />
<Tab.Screen name={DATA_ATTACHMENT} component={Lessonintro} />
</Tab.Navigator>
</NavigationContainer>
</View>
解决方案
只需通过回调而不是 Direct Compnent
像这样
<View>
<NavigationContainer>
<Tab.Navigator>
// just pass it as a props in the component that is being return from callback
<Tab.Screen name={COURSE_INTRODUCTION} component={()=><Adddata exampledata={example}/>} />
<Tab.Screen name={COURSE_VIDEO} component={()=><LessonVideo exampledata={example}/>} />
<Tab.Screen name={DATA_ATTACHMENT} component={()=><Lessonintro exampledata={example}/>} />
</Tab.Navigator>
</NavigationContainer>
</View>
在 Respective Child Components 中,您可以使用
this.props.exampledata
或props.exampledata
根据您要访问数据的类组件或无状态组件分别使用什么。
推荐阅读
- python - 有没有办法在字符串中获取特定行
- javascript - 错误:Route.get() 需要一个回调函数,但得到了一个 [object Object]。用 Chai 测试 router+res.render 函数
- java - Spring Boot 组织级角色和权限
- flutter - 使用 RawKeyboardListener 在 Flutter Web 中获取没有文本字段焦点的按键值
- python - 在python中递归返回一个三元似乎不起作用
- google-apps-script - 谷歌表格脚本 .flush() 问题/梦想?
- scala - 单元测试无法得到预期结果,代码如下
- python - 为我正在学习的 Django/Python 课程创建的应用程序中的路径/URL 错误
- python - 缺少 C3.ai COVID-19 数据湖的身份验证令牌
- c++ - 如何停止接受任意数量的输入?