Mihir
Mihir

Reputation: 155

Reduxjs or simply state

I have often heard questions that ' Why one should use redux whether there is also a State in the ReactJs. Which extra facilities redux does provide to the developer ? '

Upvotes: 1

Views: 76

Answers (3)

Hemadri Dasari
Hemadri Dasari

Reputation: 33984

Redux is required when your application is big with many components. Redux works as global meaning if you set value in one component you can get that value across components. This is the primary advantage with state management Library.

If your application is small with 10 to 20 components then we don’t need redux. We can pass down state to child components as props but when application grows big you will have so many components and it’s very difficult to play with component level state and you won’t have control of the flow and you can’t track of values between components

So redux is very useful in such cases.

Upvotes: 1

C. Jones
C. Jones

Reputation: 21

The Redux docs page about organizing state (here), list out a few reasons one might lean to using Redux store over component state. However, they do clearly state that "using local component state is fine" and that, in the end, the developer should find the proper balance for the work at hand.

Some common rules of thumb for determining what kind of data should be put into Redux:

  • Do other parts of the application care about this data?

  • Do you need to be able to create further derived data based on this original data?

  • Is the same data being used to drive multiple components?

  • Is there value to you in being able to restore this state to a given point in time (ie, time travel debugging)?

  • Do you want to cache the data (ie, use what's in state if it's already there instead of re-requesting it)?

Upvotes: 2

annejode
annejode

Reputation: 21

For small applications when there aren't a lot of components, you can do without redux. But in large applications, it becomes pretty complicated/tedious to chain props through components especially if one that is deep 6 levels needs it. This is a great article that explains it

https://blog.logrocket.com/why-use-redux-reasons-with-clear-examples-d21bffd5835

Upvotes: 2

Related Questions