简体   繁体   中英

Storing and loading data from react-native calendar to a JSON file

I'm currently thinking of a concept for a react-native app where people add events over a period of time like a diary/log. These events need to be exported and for security and privacy reasons I don't want to use a database. I've read you can use JSON files as a storage method, too.

How can I store data from the app to a JSON file and load the data from the JSON file back in the app? Don't need any code, helpful articles or webpages are appreciated

Assuming that you already have all the app data into a json, its rather simple.

  1. Decide where to store the appdata.json, lets call it APP_DATA_PATH
  2. Find a library to read/write files (I've only used expo-file-system )
  3. On app boot, check if APP_DATA_PATH exists, if it does read the file and load into app, if not assume its a new user
  4. Whenever app data changes, write the changes to APP_DATA_PATH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM