Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the best ways to Handle data in React-Native Mobile App?

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?

like image 409
fAiSaL Avatar asked Jan 30 '18 11:01

fAiSaL


People also ask

What are the two ways to handle data in React Native?

There are two types of data that control a component in React Native: props and state. For data that is going to change in the future, we use state. The state contains the data or information about the component.

Which of the following are the correct ways to manage data in React Native?

Common options for managing dataReact provides a hook for storing data. This is a great place to start. Redux provides a store object which maintains the application state, and can notify our React components when state changes. Redux was designed with React in mind, and has official React bindings: React Redux.

How do you persist data in React Native app?

In React Native applications, data can be persisted locally using AsyncStorage . AsyncStorage is an asynchronous, persistent, key-value storage system that is global to the entire app. Redux Persist is a tool used to seamlessly save the application's Redux state object to AsyncStorage .


1 Answers

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

like image 180
ReyHaynes Avatar answered Oct 14 '22 18:10

ReyHaynes