首页 > 解决方案 > 我想以原生反应将数据发送到子屏幕我添加了代码

问题描述

我想将数据发送到子屏幕。这是我的代码。我想将数据发送到 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>

标签: react-native

解决方案


只需通过回调而不是 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.exampledataprops.exampledata根据您要访问数据的类组件或无状态组件分别使用什么。


推荐阅读