如何将持久性道具与createAppContainer一起传递给React Navigation导航器?

时间:2019-09-08 17:35:57

标签: javascript reactjs react-native react-navigation

文档中有此example

const AppNavigator = createStackNavigator({...});
const persistenceKey = "persistenceKey"
const persistNavigationState = async (navState) => {
  try {
    await AsyncStorage.setItem(persistenceKey, JSON.stringify(navState))
  } catch(err) {
    // handle the error according to your needs
  }
}
const loadNavigationState = async () => {
  const jsonString = await AsyncStorage.getItem(persistenceKey)
  return JSON.parse(jsonString)
}

const App = () => <AppNavigator persistNavigationState={persistNavigationState} loadNavigationState={loadNavigationState} />;

现在,这很清楚。尚不清楚的是如何将其与createAppContainer which requires that you pass an object结合使用:

const AppNavigator = createStackNavigator(...);
const AppContainer = createAppContainer(AppNavigator);

因此,如果我必须将persistNavigationStateloadNavigationState传递给<AppNavigator />,但是我不能将<AppNavigator />传递给createAppContainer,则我看不到实现这一点是可能的。我在俯视什么?

0 个答案:

没有答案