React Navigation-Stack.Navigator screenProps不起作用

问题描述 投票:0回答:1

我有以下代码,该代码为2个组件LoginList创建了一个简单的堆栈导航器。我在使用导航器(useState)的文件中有一个App.js钩子,我想将setter和getter传递给每个屏幕。我曾尝试在堆栈导航器上使用screenProps,但在记录传递给每个组件的道具后,变量不会出现。

TL; DR我需要将道具从Stack.Navigator传递到每个屏幕

<NavigationContainer>
  <Stack.Navigator screenProps={{setVariable, variable}}>
    <Stack.Screen
      name="Login"
      component={Login}
      options={navOptions}
    />
    <Stack.Screen
      name="List"
      component={List}
      options={navOptions}
    />
  </Stack.Navigator>
</NavigationContainer>
reactjs react-navigation react-props react-navigation-stack
1个回答
0
投票

您需要使用React的上下文API

© www.soinside.com 2019 - 2024. All rights reserved.