Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redux vs plain React [closed]

I have been reading some redux tutorials and to be honest I do not see up until now what added value it brings over plain react.

As far as I know I can build an app and manage its state using only react, so, what makes redux something worth using?

Well, I do recognize redux has a few advantages over react, namely:

  • Keeps track of all the actions carried out;
  • Makes it easier for debugging due to the previous point;
  • Prevents state from being passed down/up between components.

But maybe due to my lack of experience building large apps I am not convinced that it would make my life easier.

Can you elaborate a little more on the advantages of using redux over plain react?

like image 620
utxeee Avatar asked Aug 31 '16 23:08

utxeee


People also ask

Does Redux reduce performance?

While it's certainly possible for each of these to become a performance concern in sufficiently complex situations, there's nothing inherently slow or inefficient about how Redux is implemented.

Should you always use Redux with React?

Using Redux also means learning how it works, which again could be a waste of time if you don't need it. As a rule of thumb - and one shared by one of Redux's creators, Dan Abramov - you don't need to use Redux unless you're unable to manage state within React or other front-end frameworks you're working with.

What is the difference between Redux and React?

Redux can be used with React. both are independent of each other. Redux is a state managing library used in JavaScript apps. It simply manages the state of your application or in other words, it is used to manage the data of the application.


2 Answers

Off the top of my head, a few advantages:

  • A lot of the time your app's state tree could be considerably different than the UI tree
  • Many components may need to access the same state and display it in different ways
  • Hot reloading components will wipe out your existing component tree, including any state stored inside of them. Keeping the state separate from the UI tree allows the UI tree to be swapped out and reloaded with the updated components, while keeping your current development state the same.

And that's before getting to many of the commonly discussed benefits, such as predictable state updates, time travel debugging, improved testability, and centralized logic.

It's certainly true that you can write an entire application using nothing but React's component state (and Dan Abramov himself says that people often jump into Redux too early), but from my perspective Redux is absolutely worth it.

edit

I've written up an expanded version of this answer as an article on the Full Stack React site: Redux and Why It's Good For You.

like image 135
markerikson Avatar answered Oct 16 '22 09:10

markerikson


To me, the biggest advantage is the fact that redux has a single state tree compared to possibly many smaller states in react only components. Together with redux' reducers, state becomes very deterministic and is easier to reason about.

like image 34
Mario Tacke Avatar answered Oct 16 '22 10:10

Mario Tacke