不赞成使用本机React的AsyncStorage



我正试图在freact 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 : {
}
});

Yes AsyncStorage已被弃用,他们建议使用其社区包之一来实现异步存储。还有另一种键值对存储类型,称为mmkv,据说比AsyncStorage更快。

请查看此链接以获取异步存储的社区包https://reactnative.directory/?search=storage

AsyncStorage现在与React Native分离。这是新的回购文件:

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 : {
}
});

最新更新