React Native: better to store large object in AsyncStore or local JSON file?

420 Views Asked by At

In my React Native app I make an API call that takes about 30s to return, because it's retrieving an object that contains about 4000 items. I want to store that object locally so that the user has to fetch it only the first time they install, rather than every time they log in. Should I use AsyncStorage for this? Or store it as a local JSON file on the device?

1

There are 1 best solutions below

2
Muhammad Usman On

There can be multiple approaches to deal with it,

If your data is dynamic, then obviously you need the API to load the data. After API calling you can store the data in either local storage or local file system

local storage has a 6MB limit of default, but you can increase this limit,

If your data size is large in size like greater than 6MB then you can use the file system to store the file, react-native-fs is the library that can help you to create and read the file to the local file system

However, if your data is not dynamic, then you can use the local JSON file to store the data, but this is will increase the .apk or .ipa size when you will upload it to the store