Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When not to use Redux in React-Native?

I have recently started working on React-Native Apps and found Redux helpful. But according to my understanding when I use Reducers (mostly for using WebServices APIs) the data is stored in App level state which could be used by Components. Wouldn't it be harsh on App Performance as all the data would be in App level state. I am confused here. Please recommend a way out. Thanks

like image 827
Navdroid Avatar asked Jan 29 '18 13:01

Navdroid


People also ask

Should I use Redux with react native?

Advantages of Using Redux In React Native Server-side rendering: Redux can also be used to render data on the server. We can use it to manage the app's initial render by providing the app's state to the server along with the server request response.

Do we need Redux in 2022?

It generally makes it easier to maintain. It also helps you segregate your business logic from your component tree. For large-scale apps, it's critical to keep your app more predictable and maintainable. Debugging is made easy Redux makes it easy to debug an application.

Is Redux unnecessary?

The short answer is no, Redux is not necessary for React applications. However, there are always clear warning signs when you should be using a state management library like Redux and signs that you shouldn't.


2 Answers

Redux single store should not affect your applications performance. The only difference is that all of your state objects are nested into a single tree, rather than stored into multiple, different and nested components.
Instead, what really affects React applications performance is the rendering process. In React, continuously updating a component local state or props can lead to a performance drop due to the consequent, sometimes, useless re-rendering. If you're really concerned about Redux performance, this article could cover most of your doubts and give you some useful insights.

like image 158
Omar Avatar answered Oct 24 '22 05:10

Omar


Yes, the data will be in a global state. That is the whole idea. To share data between two components, we need to lift state up to the common parent component. For a complex app, that will still cause data flow problems. Redux solves the data flow issues by lifting state all the way to a global state container. From the redux store, state flows down to all components via props. This encourages uni-directional data flows in React apps. Any state changes are made to the Redux store via dispatched actions. And from the global state, data flows down to both container and presentational components.

App performance is usually not an issue. I have known people using over 100 reducers and the performance is good. For the forms, it is better to have some local state for TextInput. And use onBlur to save state to redux store.

When not to use Redux? For simple apps with only a few screens, Redux may be an overkill. All that you need to do for simple apps is to have all the state in the root component or container components and let it flow down to the presentational components. If you are familiar with Redux, you can still use Redux. No harm is done. But easy to use local state for simpler apps.

like image 21
vijayst Avatar answered Oct 24 '22 06:10

vijayst