gpt4 book ai didi

javascript - 将 props 传递给 createSwitchNavigator 会破坏 createAppContainer

转载 作者:行者123 更新时间:2023-12-01 01:14:52 25 4
gpt4 key购买 nike

以下代码在我的 expo React Native 项目中运行良好:

const AppNavigator = createSwitchNavigator({
Loading:Loading,
Auth: AuthenticationNavigator,
Main: MainNavigator
});

const AppContainer = createAppContainer(AppNavigator);

class App extends React.Component {
render() {
return <AppContainer/>
}
}

我想将 screenProps 添加到我的 createSwitchNavigator 中。我用过this example 。这是我的代码:

const AppNavigator = createSwitchNavigator({
Loading:Loading,
Auth: AuthenticationNavigator,
Main: MainNavigator
});
const AppNavigatorWithProps=(<AppNavigator screenProps={{testing:true}} />)

const AppContainer = createAppContainer(AppNavigatorWithProps);

class App extends React.Component {
render() {
return <AppContainer/>
}
}

我收到以下错误:

TypeError: undefined is not an object (evaluating 'Component.router.getStateForAction')

This error is located at:
in NavigationContainer (at App.js:42)
in App (at withExpoRoot.js:22)
in RootErrorBoundary (at withExpoRoot.js:21)
in ExpoRootComponent (at renderApplication.js:34)
in RCTView (at View.js:44)
in RCTView (at View.js:44)
in AppContainer (at renderApplication.js:33)

我做错了什么?

最佳答案

class App extends React.Component {
render() {
return <AppContainer screenProps={{ testing: true }} />
}
}

像这样

关于javascript - 将 props 传递给 createSwitchNavigator 会破坏 createAppContainer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54860261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com