Navdroid
Navdroid

Reputation: 1549

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

Upvotes: 7

Views: 8947

Answers (3)

Evalds Urtans
Evalds Urtans

Reputation: 6704

As I see it (only my opinion):

  • Redux / Flux / Functional programming
    • More defragmented logic (store, actions, reducer, view, view controller, middlewares). Harder to reuse parts of app (will need to copy and edit large number of source code files)
    • "White box" logic. Unidirectional flow of execution, great tools for testing actions, states & replicating problems
    • Harder to handle multi-threading, but still possible. Need to use functional actions.
    • More logic executed on client (one of the reasons Facebook developed it)
    • Well suited for large or collaborative UI apps
  • MVC / OOP
    • More united logic (model, view, controller). Much easier to reuse parts of app.
    • "Black box" logic. Flow of execution not controlled. Could end up in deadlocks, infinite loops, hard to replicate states and problems.
    • Easier to handle multi-threading.
    • More logic executed on server
    • Structure well suited for small or reusable UI apps

Regarding non-UI apps: OOP is much more well suited for making reusable non-UI libraries or apps without transactional / event nature. Currently, almost all of the libraries for non-UI apps are still built in OOP. It would make life difficult to combine these two worlds. Maybe in future, all will change, but for now, I would not recommend using Redux / Flux for non-UI apps.

Upvotes: 2

Omar
Omar

Reputation: 16623

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.

Upvotes: 6

vijayst
vijayst

Reputation: 21864

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.

Upvotes: 3

Related Questions