react-native - 基于 redux 状态有条件地在选项卡导航器中渲染不同的堆栈导航器
问题描述
我的应用程序有一个底部选项卡导航器,其中一个选项卡(Rep)需要根据 redux 状态呈现不同的堆栈导航器。通过在成功验证后运行查询并导航到默认屏幕 (MyPathScreen) 来设置状态。
我尝试实施以下方法:
const isRep = useSelector(selectIsRep);
return (
<Tab.Navigator
initialRouteName="My Path"
})}>
<Tab.Screen
name="Rep"
component={
isRep ? RepNavigator : RepApplicationNavigator
}
options={{
tabBarLabel: 'Rep',
}}
/>
<Tab.Screen
name="My Path"
component={PathNavigator}
options={{
tabBarLabel: 'My Path',
}}
/>
<Tab.Screen
name="My Account"
component={MyAccountNavigator}
options={{
tabBarLabel: 'My Account',
}}
/>
</Tab.Navigator>
);
};
TabNavigator
但是,在每次登录和注销时,我都会收到以下错误:警告:在呈现不同的组件 () 时无法更新组件 ( MyPathScreen
)。我究竟做错了什么?如何避免此错误?
解决方案
After some experimenting, I solved this issue with wrapping my dispatch in useEffect.
推荐阅读
- pine-script - 如何将系列中的所有 y 值更改/覆盖为 Pine Script 中的单个数字?
- git - 是否命令“git reset --hard
" 删除另一个分支的提交历史? - algorithm - 求解 3 个方程、2 个未知数系统的最小化算法
- javascript - 将选择显示到 SVG 矩形 (JavaScript)
- reactjs - resetForm 不是函数,为什么会出现此错误?
- sql - 处于还原模式的 SQL 数据库
- c# - uwp中的按钮在我启动时不显示
- c++ - 新的 VS C++ 更新使 boost forward 声明的代码不可编译!你能做什么?
- c++ - 使用 C++ 的 N-Queens 算法
- c# - Windows 窗体应用程序不会在启动时运行,但会手动运行