4 ms·
For me, there's a peace of mind associated with knowing that all my state is in one place in an organized format. It's like having a db, but on the front end,
by dhbradshaw 9y ago
For me, there's a peace of mind associated with knowing that all my state is in one place in an organized format. It's like having a db, but on the front end, and it makes testing the front end very nice. It also has other practical benefits.
Specifically, 1) it makes rapid iteration simpler because I don't have to click back to the portion of the app that I'm testing but can instead just rehydrate a cached state, and 2) it makes it trivial to save state for the user either by caching it locally in the browser or by sending it over to the back end.
- celim307 9y ago> It's like having a db, but on the front end This.
- JonathonW 9y agoWhy do I need Redux for that, though? I'm working on a fairly small but still nontrivial React app for work (it's the first time we've used React for anything here, and we're partly doing it to evaluate React for future work). I've not used Redux anywhere in my application (it's all vanilla React), but my state is still all in one place in an organized format, and, since I have a single component managing my state, I can still trivially do both (1) and (2) there. What's Redux giving me that I don't already have, aside from another layer to maintain and another piece to break?
- acemarke 9y agoI wrote an article a while back that describes some of the possible benefits for using Redux in a React app: https://www.fullstackreact.com/articles/redux-with-mark-erikson/ https://www.fullstackreact.com/articles/redux-with-mark-erik... . Quick summary: you don't have to pass data as props all the way from the top of your app to the bottom, and it lets you keep your app state if you're doing hot module reloading in development. In addition, time-travel debugging and the action history log really are powerful tools for understanding how your app is behaving over time. My other comment just below this discusses some more benefits, and links to Dan's "You Might Not Need Redux" post. I'd encourage you to read that as well.
- rand_r 9y ago> you don't have to pass data as props all the way from the top of your app to the bottom Quick note, you can accomplish this directly using the "context" feature of React, which is what Redux uses under the hood anyway. https://facebook.github.io/react/docs/context.html https://facebook.github.io/react/docs/context.html
- acemarke 9y agoYeah, I was keeping the explanation shorter. The React docs generally advise that apps try not to use context directly, as the API has limitations, and _will_ change in some future React release once they figure out a better approach. The main issue is that context updates are blocked if a component returns `false` from `shouldComponentUpdate` (and the same for a PureComponent). As a result, context is best suited for references that won't change, such as pubsub event emitters. Michel Weststrate's post "How to safely use React context" [0] is excellent, and Ken Wheeler just gave a good talk about context at React Boston [1]. [0] https://medium.com/@mweststrate/how-to-safely-use-react-context-b7e343eff076 https://medium.com/@mweststrate/how-to-safely-use-react-cont... [1] http://reactboston.surge.sh/#/ http://reactboston.surge.sh/#/
- worldsayshi 9y agoAs someone who went from using context to using redux, you can really shoot yourself in the foot with contexts. With redux we can breath again. Contexts is useful for anything that rarely changes. Like callbacks. But if you want to send down stateful things it will quickly become a mess for complex apps.
- onion2k 9y ago"I don't need redux because I implemented something to do the same thing it does myself" is not an argument against redux. You may not like redux but you do understand it's doing something necessary, so people who like it's implementation should probably use it.
- deckard1 9y ago> It's like having a db, but on the front end eh. Not really. Because there is no schema, what happens is the Redux store turns into a mess. You got 10, 20, 30 developers working on an app, no one has a clue what any of the Redux variables mean or what use-case they are for (or what use-case they may change), and worse you have redundant data scattered everywhere and you're never sure which should be the authority. It's an ad hoc global variable soup that is updated with the moral equivalent of GOTOs (Redux actions) that litter the code in just about everywhere you could possibly think of.
- dhbradshaw 9y agoRight. It's like a db iff you have and enforce a convention to keep your data organized.