I've worked with Redux for some time now. I fail to see the hype around Redux being given prominence even while building a fairly low-level complexity apps, like a phone-book web app.
Personally, as a React/Redux developer where do you draw the line between; "Yes, this app can do with having the state in a top level component" and "Nah, this app is complex enough that it needs something for state management ala Redux"?
Hi,
i always read such posts as if implementing redux is that big of an overhead like adding Ember or Backbone or any framework to your app. Redux simplifies managing your store, so even it's a small app, why not add redux to it? It makes sense all over the place. Redux is just plain functions, so no overhead, it's more a way to structure your app than any framework.
So: If you like redux and understand it, use it.
There is no line. Everything gets evaluated on a case-by-case basis... and even on a class-by-class basis.
At one end of the spectrum, I've written a simple 4-page almost-static doctor's office site that uses Redux to manage page titles and the logic around office hours and whether the office is currently open or closed. It's very very simple code and I could have easily written it without Redux... but as another user said, there's very little overhead and if you like it and understand it then use it.
At the other end, I'm currently working on a much larger digital asset management application and I have a component that allows the user to visually arrange the layout. I chose to not use Redux for some state (cursor position, drag states, hit testing, etc) because it felt like overkill -- specifically a lot of ceremony to create an action, figure out how I want to store the data, add cases to a reducer, add more selectors, passing values in mapStateToProps, etc. instead of just assigning to a local variable and being done.
I think the limit is the same when you need components in place of jQuery &al. Is just about abstraction.
If you prefer to think your app as states, then you need a tool (custom or not) to manage the states and the transitions state of your app: redux, mobx, alt...
If you prefer to think your app as an assembly of independants components, forget global store and use react state.
The problem when you use a top lvl component as a store is the scalability. I think if you have to pass some states as props to much deeper (3lvl) tought your app, it means something going be wrong. Like the z-index in css (if you have more than 3 lvl of z-index... Hum, good luck to maintain this dude). So go ahead if you can do your app with having 3 lvl of components or less, than forget global store (redux and al.).
Cheers !
I personally draw the line at running
npm init, but I'm kinda biased :)More seriously, while you certainly can write a React app with only component state, and there's nothing wrong with doing so, using Redux (or even another state management library like MobX) can have a number of benefits. I wrote a Stack Overflow answer on "Redux vs plain React?" a couple months ago, which I'll paste here for reference:
You may also want to read the Redux FAQ entry on When should I use Redux?.