【问题标题】:AsyncStorage are deprecated using React native使用 React native 不推荐使用 AsyncStorage
【发布时间】:2022-01-03 21:20:18
【问题描述】:

我正在尝试在 fract native 上使用 MQTT,因此当我尝试从已弃用的 react native 导入它时,我不得不在我的代码中使用 AsyncStorage。请帮忙。

 import init from 'react-native-mqtt'
 import { AsyncStorage } from 'react-native'

init({
  size: 10000,
  storageBackend: AsyncStorage,
  defaultExpires: 1000 * 3600 * 24,
  enableCache: true,
  reconnect: true,
  sync : {
  }
});

【问题讨论】:

标签: reactjs react-native mqtt asyncstorage


【解决方案1】:

是的 AsyncStorage 已弃用,他们建议使用其社区包之一来实现异​​步存储。还有另一种键值对存储类型,叫做 mmkv,据说比 AsyncStorage 快。

查看此链接以获取 AsyncStorage 的社区包 https://reactnative.directory/?search=storage

【讨论】:

    【解决方案2】:

    AsyncStorage 现在与 React Native 分离。这是新的 repo 文档:

    https://react-native-async-storage.github.io/async-storage/docs/install/

    用法:

    import init from 'react-native-mqtt'
    import AsyncStorage from '@react-native-async-storage/async-storage';
    
    init({
      size: 10000,
      storageBackend: AsyncStorage,
      defaultExpires: 1000 * 3600 * 24,
      enableCache: true,
      reconnect: true,
      sync : {
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-23
      • 2018-08-12
      • 1970-01-01
      • 2020-11-09
      • 2018-01-01
      • 1970-01-01
      • 2019-12-09
      相关资源
      最近更新 更多