备用以响应本机AsyncStorage以在设备中保存应用程序数据

问题描述 投票:0回答:2

我在React Native中创建了一种Quote应用程序,使用rest api获取应用程序数据。我在应用程序中有一个最喜欢的功能,用户可以喜欢或不喜欢报价。用户没有登录到应用程序,所以我想在他点击收藏夹图标时特定报价在本地应用程序中保存在收藏夹屏幕中,并且在用户重新启动应用程序或设备时可用。最可能的选择是什么?现在我正在使用React本机AsyncStorage,但是它运行不正常,有一些奇怪的错误。所以我正在寻找它的替代方案。

react-native react-redux offlineapps asyncstorage
2个回答
0
投票

你可以使用Sqlite。它是一个本地数据库,因此只有用户才能访问。 https://github.com/andpor/react-native-sqlite-storage 或者如果你正在使用世博会: https://docs.expo.io/versions/latest/sdk/sqlite/ 例:

const db = SQLite.openDatabase('quotes.db'); db.transaction(tx => { tx.executeSql('create table if not exists quotes(id integer primary key not null, favoriteQuote text);'); tx.executeSql('SELECT * from quotes ', [], (_, { rows: { _array } }) => {console.log(_array)})})


0
投票

你可以使用realm,它很容易强大和易于使用,它有一个非常好的documentation

© www.soinside.com 2019 - 2024. All rights reserved.