0

This is more of an architecture/stack question that anything.

A simple study time tracker - The app should need a connection at first to create an account or sign in, But once they do so it should be fully offline

  • The app should require a connection to create an account and sign in
  • After that everything should be stored locally and be accessed that way
  • This local data should update a database on a server periodically (every day at 12am or something)

So my question is - What should i use to store and persist state in react native and what can i use to have this data synced to a database at certain intervals?

1 Answers1

0

First, to save data locally, you can check out this answer which mention specifically this.

Saving data locally you should set an attribute to track if this data is sync or not, ( e.g _synced: false )

Now, to make syncs happening you shouldn't rely on a specific daily hour to do it, as if the user lost his connection in that hour, the app wouldn't sync its data.

Take a deep read into this react-sync-adapter extension that syncs your app's data based on a timeout, you can change this sync to be foreground and background.

Using this, you create a function to be executed every x seconds, then in this function you'd get all the non-synced data ( _synced === false ) and after syncing it set this data to true. This way the next sync's will be smoother

Felipe Malara
  • 1,796
  • 1
  • 7
  • 13