gpt4 book ai didi

javascript - createSwitchNavigator-TypeError : Cannot call a class as a function

转载 作者:行者123 更新时间:2023-11-30 14:13:57 30 4
gpt4 key购买 nike

我在尝试将 createSwitchNavigator() 插入 createAppContainer() 时收到此错误消息。

TypeError: Cannot call a class as a function

我的代码 - router.js

export const RootNavigator = (signedIn = false) => {
return createSwitchNavigator(
{
SignedIn: {
screen: SignedIn
},
SignedOut: {
screen: SignedOut
}
},
{
initialRouteName: signedIn ? "SignedIn" : "SignedOut"
}
);
};

export const createRootNavigator = createAppContainer(RootNavigator());

索引.js

import { createRootNavigator } from "./router";

/**/

const Layout = createRootNavigator(signedIn);

引用:https://github.com/datomnurdin/auth-reactnative

最佳答案

您正在尝试将一个函数返回给createAppContainer,但它需要一个create*Navigator

的实例

要么用作

export const RootNavigator = createSwitchNavigator(
{
SignedIn: {
screen: SignedIn
},
SignedOut: {
screen: SignedOut
}
},
{
initialRouteName: signedIn ? "SignedIn" : "SignedOut"
}
)

export const createRootNavigator = createAppContainer(RootNavigator());

编辑

用于调用 createRootNavigator 作为方法

export function createRootNavigator (signedIn) {
return createAppContainer(RootNavigator(signedIn));
}

index.js

const Layout = createRootNavigator(signedIn);

关于javascript - createSwitchNavigator-TypeError : Cannot call a class as a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53911269/

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