6

Since I'm from a Objective-c / Swift background and new to React and React-Native, it's difficult to sink into the new environment. I had a couple of research on React-Native, which helped me to understand some basic concepts like components, States, props etc.

I am stuck at the part where how the React-native apps handles the data, like storing and fetching. In ios, we can use core data framework to handle all those stuff. During those research, I came across Redux & AsyncStorage. Most of the tutorials recommend using Redux for storing data. But What I understood is that they help to store or handles States of the application and AsyncStorage is used only as a key-value storage.

From an iOS developer point of view, what could be the best solution in handling the data when coming to a React-Native app (Like coreData).

I did have a peek at this query:

What are my options for storing data when using React Native? (iOS and Android)

But I'm not satisfied with the solution. Could anyone please help me out here?

fAiSaL
  • 754
  • 1
  • 10
  • 29
  • The solution you mention is pretty comprehensive. What do you feel is missing? – Kraylog Jan 30 '18 at 12:05
  • @Kraylog if I have a large amount of JSON data (or whatever) to store, will Redux or AsyncStorage will help me to achieve it. Correct me if I'm wrong since am a newbie at React. – fAiSaL Jan 30 '18 at 12:16
  • 1
    Redux is an in-memory store, so that's probably not what you're looking for. AsyncStorage is basically an abstraction layer over persistence mechanisms in iOS and Android (a file and a simple file db). You can probably store most things there, to a point. – Kraylog Jan 30 '18 at 12:39
  • 1
    Storage solutions in the React Native ecosystem are much more modular and dependent on understanding your use case because any solution needs to expose a unified API for both iOS and Android. As such, it's much more difficult to bridge the various implementation differences in the two ecosystems. So if you're looking for an all encompassing API like *core data*, you won't find one at the moment. Answering your question is... difficult to say the least. I've attempted it but left my article unfinished. That link is the best overview right now. To better help, how do you define "best"? – Michael Cheng Jan 30 '18 at 13:47

1 Answers1

2

I know it's already in the associated link you supplied but just adding redux-persists with redux handles most of the storage requirements for iOS, Android, Electron and Web apps.

As for the complexity, at the end of the day, in most storage engine cases, it's all JSON stringified under the hood so nesting isn't much of an issue if you need a more complex dataset.

redux-persists manages the storage engine for you.

More info: https://github.com/rt2zz/redux-persist#storage-engines

ReyHaynes
  • 2,932
  • 1
  • 15
  • 22
  • 3
    Caveats since the OP mentioned a large amount of JSON data in a comment: 1) [you do not want to use this for large datasets](https://github.com/rt2zz/redux-persist/issues/185) 2) this is only applicable if you use Redux for state management (the OP appears to not understand the distinction between Redux/state/props and how storage is done ala core data) 3) while a great module, selection of your storage engine is left up to you which would leave OP back in their original situation of not understanding the best way to handle certain use cases. – Michael Cheng Jan 30 '18 at 13:45
  • @MichaelCheng 1) Agreed. Didn't refresh before responding to see the large dataset comment. 2) Subjectively you can use redux for core-data if you manage correctly but you are right, there needs to be an understanding of the differences before doing so. Great response! – ReyHaynes Jan 30 '18 at 13:58
  • @MichaelCheng The link seems like the same issue I will face if I go forward with the storage of redux for a huge amount of data. I'm still researching here for a better solution. Appreciate your response. – fAiSaL Jan 31 '18 at 05:43
  • @MichaelCheng Will it be good if I use Realm along with Redux. Most of the sources say that Realm is good if we are dealing with a large amount of data or simply require a faster local storage. – fAiSaL Jan 31 '18 at 11:07