Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create offline first apps with React-Native?

From what I've understood offline first apps need a way to tell if the user is connected; if not, it stores changes locally and syncs with the remote server when online.

The way I've found to do this with web apps is by using pouchdb on the client communicating with an api connected to a couchdb database. Or by using Firebase.

Is it possible to have similar functionality using React-Native? Maybe by using the pouchdb-async-storage adapter. Are there other alternatives out there for local-remote data syncing?

like image 546
HairLessDude Avatar asked Oct 26 '15 03:10

HairLessDude


2 Answers

I build an AsycStorage Adapter for PouchDB, including Polyfills for React-native. Properly that helps.

asyncstorage adapter for PouchDB

like image 141
stockulus Avatar answered Oct 12 '22 19:10

stockulus


I haven't actually implemented offline capabilities in a React-Native app but from looking at the docs, the APIs provided enable you to do so.

The APIs you're looking for are AsyncStorage (for data persistence) and to detect the connection info use NetInfo.

You're on the right track about using pouchdb. The part you will most likely have to write yourself is the syncing script (I'm not sure you can do this in the background but I may be wrong).

Let me know how you get on or if you want to discuss further @hugo__df on twitter :)

like image 41
Hugo Avatar answered Oct 12 '22 20:10

Hugo