react-native - 持久补液后记录用户
问题描述
我正在尝试在 Rehydration 后在 react-native 中登录用户。在商店中有数据后,我不确定如何重定向用户。
以下是我在 index.js 文件中设置 PersistGate 的方法:
class AppRedux extends React.Component {
render() {
return (
<Provider store={store}>
<PersistGate persistor={persistor} loading={<SplashScreen />}>
<App />
</PersistGate>
</Provider>
);
}
}
AppRegistry.registerComponent(appName, () => AppRedux);
SplashScreen.js:
class SplashScreen extends Component {
constructor(props) {
super(props);
props.navigation.navigate(RouteNames.Home);
}
render() {
return <View style={{ flex: 1, backgroundColor: "green" }}></View>;
}
}
const mapStateToProps = state => {
return {
rehydrated: state.user.rehydrated
};
};
export default connect(mapStateToProps)(SplashScreen);
这种方法的问题是我无法从启动屏幕导航。我得到导航道具未定义。
解决方案
“PersistGate”中的“loading”道具只是一个虚拟组件,用于显示加载程序,直到 Persist Rehydration 。“App”(导航组件)将在 Rehydration 之后加载,您可以在其中接收“导航”道具并可以访问商店。
像官方网站Auth Flow中描述的那样试试这个
创建 AuthLoading 屏幕并从那里设置导航
应用程序.js
const AppStack = createStackNavigator({ Home: HomeScreen, Other: OtherScreen });
const AuthStack = createStackNavigator({ SignIn: SignInScreen });
export default createAppContainer(
createSwitchNavigator(
{
AuthLoading: AuthLoadingScreen,
App: AppStack,
Auth: AuthStack,
},
{
initialRouteName: 'AuthLoading',
}
)
);
推荐阅读
- ios - 如何使用 XIB 在 UITableView 中使用静态单元格的数量
- asp.net-mvc - 如何从 ASP.NET MVC 5 应用程序中的库执行后台任务
- android - 输出视频有黑色..这个命令有什么问题?
- javascript - 可以在 Sequelize 中嵌套包含的 WHERE 上吗?
- c# - 多个字符串在正则表达式中有特殊字符
- android - 由于资产资源文件夹中的地图字体,Apk 大小增加了 40mb(使用 tomtom api 进行地图)
- qt - 鼠标悬停事件在 TableView 的标题中不起作用
- flutter - 英雄小部件多次初始化子小部件
- pgadmin-4 - pgadmin4 无法正确显示
- ios - 如何使用单个自定义单元格用两个数组填充表格视图?