AsyncStorage in React Native: Something You Should Know

Last year, we made the decision to use React Native in order to build the mobile app for our product, Secure Data Kit. Suffice it to say, we are happy with the choice we made. Being a small team of web developers, we needed a platform that allowed cross platform compatibility since we needed this app on both iOS and Android. We wanted to make sure we supported all of our users, regardless of the type of device they owned. For our situation, which I doubt is atypical, React Native was the best solution. Essentially, it allowed us to use JavaScript to write the application code, which React Native then used to produce the native code which would run on each platform. It's pretty sweet to see in action, and I recommend anyone in need of some native app development to check it out.

Now, while React Native is great, it is not perfect. One specific issue we had was with AsyncStorage. More specifically, we had an issue with the documentation for AsyncStorage. It turns out that AsyncStorage on the Android platform has a limit of 6MB. Exceeding that limit, will cause the app to crash. This limitation only exists on Android, as iOS will let you store as much data in AsyncStorage as you want. I guess our issue is with the fact that this wasn't explained in the documentation at all. The 6MB limit is not even mentioned. We only learned about it after we were experiencing crashes in the field. Through troubleshooting I found myself on this GitHub issue page, where the limit is explained. Well, it is not so much explained, as it is just made clear that the limit exists. In order to fix our problem, we eventually had to write our own storage solution using SQLite. Had we have been aware of the limitation with AsyncStorage, we would have implemented the use of a relational database at the beginning of development. In my opinion, it would have been great if the official documentation would have made this clear.

Aside from that snag, we have been really happy with the apps we were able to build using React Native, and I really do recommend it for anyone that needs a native mobile app for their product. I just hope that the person gets a chance to read this tidbit before choosing AsyncStorage as their primary storage solution.



Matt
Apr. 24 2018