Keep data in offline app React Native

假装没事ソ 提交于 2019-12-23 02:29:22

问题


I want to create offline an alphabet app for children using React-Native, and I want to ask you what is the best way to store data about each letter, for example: letter ID, letter NAME, letter IMG_SRC etc. I thought about using JSON, but as well decided to ask you about it. May be there's a better way. I'll be very happy if you share your own experience with me)


回答1:


The easiest way to store offline data is using the AsyncStorage, it's basically a key value storage, super easy to use. You can save json in there or any other text, for example:

AsyncStorage.setItem('data', JSON.stringify([{id: 1, name: 'a', src: ''}]));

Then, later on, you can get that data like this:

AsyncStorage.getItem('data', (err, result) => {
  console.log(JSON.parse(result));
});

For simple apps, this is more than enough



来源:https://stackoverflow.com/questions/48571223/keep-data-in-offline-app-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!