9

This question was asked on GitHub, with the answer being "Hey, have you heard of this website Stack Overflow? You should ask the question there!".

So here I am, asking a question!

Does React Native support Indexed DB?

When refactoring an existing web-application to support react-native, does one have to forgo Indexed DB support? Or, does Indexed DB work out of the box?

What is the reason for the answer to the above question? Does Indexed DB not work simply because we're not in a browser and React Native doesn't currently implement that API? Can we polyfill Indexed DB in React Native? Or, should we turn to alternative persistence methods for this platform?

I am asking this as a technical lead, wanting to know whether or not react-native is going to be an easy or difficult transition for our team.

Bryan Rayner
  • 4,172
  • 4
  • 26
  • 38

5 Answers5

5

No, as of now React Native doesn't support IndexedDB.

For persistent storage in React Native the options are:

AsyncStorage: The easiest way to store objects, provides Key-value based asynchronous APIs to store data. Only provides basic get-put APIs, not suitable for search queries.

Realm: Fully fledged document oriented mobile database with the capacity for complex queries. Has both Pro and free open source editions. Best option for developing offline applications synchronised with the server.

Mostafiz Rahman
  • 8,169
  • 7
  • 57
  • 74
0

I don't think react-native currently supports it, but if you want data to persist you can always use AsyncStorage: https://facebook.github.io/react-native/docs/asyncstorage.html

or if you're using redux, you can use redux-persist.

Matt Aft
  • 8,742
  • 3
  • 24
  • 37
0

I'm giving a chance to realm.io.

There is a very very expensive licensing for pro, but it's basically free and open source so you can freely try without limitations if you don't use their platform.

Here specific and official doc for react native: https://realm.io/docs/javascript/latest

realtebo
  • 23,922
  • 37
  • 112
  • 189
0

Pouchdb is another way to use indexeddb in web and react-native.

Pouchdb work in any browser support indexeddb or webSQL if not support. On the react-native pouchdb have an adaptor to connect to sqlLit.

On any environment your code is same.

Hossein Mohammadi
  • 1,388
  • 11
  • 16
0

If you're using Expo, you also have expo-sqlite but it does get flakey at times and their API is hard to work with. I had to wrap it so I can make it work with async await.

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265