我想知道是否必须这样做,才能在react-native 应用中使用AsyncStorage保存整个应用store ,并在应用启动时判断它是否存在.

var store;

_loadInitialState = async () => {
  try {
    var value = await AsyncStorage.getItem(STORAGE_KEY);
    if (value !== null){
      store = value;
      console.log('Recovered selection from disk: ' + value);
    } else {
      store = configureStore({});
      console.log('Initialized with no selection on disk.');
    }
  } catch (error) {
    console.log('AsyncStorage error: ' + error.message);
  }
};



export default class App extends Component {

  componentWillMount(){
    this._loadInitialState().done()
  }

  render(){
    return(
      <Provider store={store}>
        <AppContainer/>
      </Provider>
    )
  }
}

这不管用,但我希望你能明白.

推荐答案

使用redux-persist,这样就不必直接使用异步存储.

React-native相关问答推荐

如何在Reaction Native DrawerNavigation中添加注销功能

react 在顶部选项卡导航中传递本机数据

我们如何才能将我们自己的应用程序(IOS)排除在共享表中?

错误:HostFunction 中的异常: Malformed calls from JS: field sizes are different. In an Animated View

react-native 自定义视图,原生 prop 没有 propType

React Native 响应式图像宽度,而图像的宽度/高度比保持不变

React-native,iOS模拟器停止响应CMD + D

如何在 react-native 中在图像周围添加阴影

api.get(...).then(...).catch(...).finally 不是函数

Android 构建错误AndroidManifest.xml requires a placeholder substitution

try 在 Android 上运行我的 React Native 应用程序时出错

React Native:当我从 XCode 运行应用程序时看不到 console.logs

react-native run-ios 运行失败: Application is unknown to FrontBoard?

Ipad 上的 React Native - 错误 - could not connect to development server

占位符文本在(多行)TextInput for Android(React Native)中的位置

xcode 10错误:multiple commands produce

INSTALL_FAILED_INSUFFICIENT_STORAGE 运行 npm run android 命令时出错

键盘可见时无法单击按钮

在 React Native 中检测向左滑动

react-native 开始给出 Invalid 正则表达式无效错误