11 ms·
Redux – Not Dead Yet (2018)
- acemarke 7y agoOh hey, that's my post. I first wrote it back in 2018, and just updated it yesterday with some additional links and comparisons. (Actually was considering retitling it after getting some feedback last night, but given that the link just got submitted here, I'll leave it as-is for now.) A few quick notes: - If you haven't looked at Redux in a while, please try out our official Redux Toolkit package [0], which is now our recommended approach for writing Redux logic, and the React-Redux hooks API [1]. We're going to be teaching both of those as the default approach for using Redux going forward. - We have a new "Style Guide" docs page that gives our official guidance on suggested usage patterns [2] - On that note, I'm working on an ongoing major rewrite of the Redux core docs [3]. My current task is creating a new "Quick Start" tutorial, which will be a "top-down" intro to using Redux to stand alongside the existing "bottom-up" tutorial sequence. The goal of the Quick Start section is to quickly introduce Redux concepts, and show RTK and hooks as the "right way to write Redux code", without going into the details of how it works under the hood, so that folks can get started now and learn the underlying aspects later. I've an early partial WIP draft PR up [4], and hope to finish the first draft in the next few days. Once the Quick Start page is done, I'll be turning my attention to rewriting the main tutorial sequence in order to remove outdated terms, clarify explanations, and teach simpler patterns (like using "ducks" files instead of splitting code across multiple files). If anyone's got questions on anything I wrote in the article or otherwise Redux-related, ask away! [0] https://redux-toolkit.js.org https://redux-toolkit.js.org [1] https://react-redux.js.org/api/hooks https://react-redux.js.org/api/hooks [2] https://redux.js.org/style-guide/style-guide https://redux.js.org/style-guide/style-guide [3] https://github.com/reduxjs/redux/issues/3592 https://github.com/reduxjs/redux/issues/3592 [4] https://github.com/reduxjs/redux/pull/3740 https://github.com/reduxjs/redux/pull/3740
- Ozzie_osman 7y agoThat was a great article—wish I had read it back in 2018! I'll chime in with some thoughts, as someone who has built several apps using React/Redux. What's happened with me (and others I've seen) has been discovering Redux, falling in love, and thinking "I'll use it for everything!" There's something about the simplicity of having a single state tree, that is immutable and debuggable that just blows your mind. Then you start building, and after writing your Xth action/reducer/selector/dispatch/etc, you tire of the boilerplate and the overhead. So where I've landed is: 1) we use Apollo/GraphQL for data-fetching and caching. 2) we use hooks in general. 3) for deeply nested component communication, we haven't fully settled on whether to use redux or not and kind of mix it up depending on the circumstance 4) we use redux when we need app-wide state and/or debuggability (so everything that's not 1, 2, or 3). This has worked pretty well for us, though (3) is still a little fuzzy. Anyway, I do think Redux is awesome, so thanks for maintaining it. But just wanted to chime in that I think a lot of "Redux is dead" sentiment (besides just being article click-bait and sensationalism by publishers) is actually people realizing that they've done the "everything is a nail" thing and retreating a little bit from that.
- acemarke 7y agoYeah, as I tried to make clear in the post, there's many other excellent tools and libraries in the ecosystem, and they _do_ overlap with the kinds of use cases that might have made people pick Redux in the past. For the record, I've never wanted _everyone_ to use Redux, and I agree with criticisms that Redux has been frequently over-used. All I want is for folks to look at their use cases, take the time to evaluate tools, and make intelligent decisions about what tools best solve their problems. Unfortunately, the nature of social media and the development community just doesn't seem to work that way. No one seems to write posts saying "here's a new tool, here's how it compares to existing tools, and here are the tradeoffs involved and the use cases where they might each be relevant". It's always "LOL TOOL X IS DEAD NOW!", even if Tool Y is brand new and has 10 downloads and 2 GH stars while Tool X's daily downloads continue to increase.
- adz_6891 7y agoThanks for sharing this, is interesting to hear what other folks are doing in practice! We were actually thinking of migrating to something similar in terms of data fetching to Apollo/graphql and leaving redux for more app wide state problems. Could you share any further insights on how you started organising this project? I.e. some pieces in Apollo/graphQL while maintaining a redux core, (presumably that's the core you started with?). Would be really interested. Also I share your sentiment exactly, redux isn't dead. It's still a really solid approach to state management, and in complex applications I still think it's one of the best options. Thanks and kudos to the maintainers!
- aecorredor 7y agoI’ve been loving redux toolkit so far, so great job on that! The docs are super good too, so props for wanting to improve them further. I encourage everyone to try out redux toolkit if you feel like redux is too much boilerplate. It also comes with immer out of the box, so no more crazy spread operators.
- thekemkid 7y agoDo you, or anyone else in the team or community, have a good resource you would recommend to people complaining about "too much boilerplate" in redux code? It is likely the most common complaint I see, that I understand to come from a place of people not understanding it this a tool best used for scaling and/or already big projects. Whenever I have worked with Redux in a large project, that "boilerplate" is minimal and the benefits obvious.
- acemarke 7y agoYeah, as I talked about in both the original blog post and my parent comment, we've specifically designed Redux Toolkit to eliminate the "incidental complexity" that came along with using Redux [0]: - Immer makes writing immutable updates easy, because you can write "mutating" logic like `state.todos[5].completed = true` - `configureStore` sets up a Redux store with good defaults (DevTools extension, thunks, mutation checking) in a single line of code and has easier-to-read options if you do need to tweak the config - `createSlice` eliminates the need to write any action creators or action types by hand - Our new `createAsyncThunk` and `createEntityAdapter` APIs (new in v1.3.0 [1]) simplify the common use cases of dispatching actions as part of data fetching and managing normalized data in your state Also, RTK is written in TypeScript, and designed to infer as much as possible. For example, if you declare the type of the action payload in a `createSlice` reducer, the generated action creator has its payload argument typed automatically to match. Meanwhile, the React-Redux hooks API generally requires less code than `connect` does, and is easier to use with TypeScript as well. Finally, we're now encouraging folks to use the "ducks" pattern for single-file Redux logic [2], which cuts down the number of files you might have to work on for a given feature, and using `createSlice` basically gives you ducks files for free [3]. [0] https://blog.isquaredsoftware.com/2019/10/redux-starter-kit-1.0/#dealing-with-complexity https://blog.isquaredsoftware.com/2019/10/redux-starter-kit-... [1] https://github.com/reduxjs/redux-toolkit/releases/tag/v1.3.0 https://github.com/reduxjs/redux-toolkit/releases/tag/v1.3.0 [2] https://redux.js.org/style-guide/style-guide#structure-files-as-feature-folders-or-ducks https://redux.js.org/style-guide/style-guide#structure-files... [3] https://redux-toolkit.js.org/usage/usage-guide#exporting-and-using-slices https://redux-toolkit.js.org/usage/usage-guide#exporting-and...
- runawaybottle 7y ago
- warp 7y agoI've recently tried using Redux for a side-project. While it solves the problem (organizing state), I feel there is too much boilerplate for my small project. Are there any popular alternatives which don't use reducers? EDIT: thanks for all the responses, I'll check them out :)
- thekemkid 7y agohooks and the context api are great for small projects. Check out the hooks comparison section in the linked article to understand how it might fit your app. It references other good resources, too.
- eropple 7y agoThere's stuff like MobX, but much of the point of Redux is the reducer step. You may be happy with just using hooks, though.
- tarcon 7y agoYou can use a React Context and have simple global state in your React app. If you like reducers, throw in a useReducer hook and you have a large part of what people use Redux for.
- bufferoverflow 7y agoI've done that recently, and I had many performance issues. I have a long-ish list of very simple components that are in a sorted order. So when I change the value of one, I re-sort the list. I was hoping React would only rerender the changed items (remove old, insert new). But no, it rerenders the whole list, which takes 500ms. I made sure object references in the list stay the same, that didn't help. I can implement this thing in vanilla JS, and it would not take more than a few milliseconds. React is cool, but so damn hard to optimize.
- runawaybottle 7y agoI don’t like the structure Redux forces my apps into. This might be a good opportunity to see what simple solutions people are using to avoid stuff like Redux. I remember reading about this: https://hookstate.js.org/ https://hookstate.js.org/
- deleted 7y ago[deleted]
- petargyurov 7y agoI am inclined to agree. At first I thought Redux was awesome, but eventually discovered that there is a lot of boilerplate and just a general overhead to doing certain things. However, I definitely fall into the cluster of people that were "just told to use Redux". For my next React project I will certainly evaluate other approaches.
- stillbourne 7y agoI really think it should die, from a DDD perspective EDA should be handled as backend tasks with CQRS. If your api server isn't handling that then you really should stand up a BFF. I get that Redux is designed to handle all of that on the front end but it just doesn't belong there. I have seen too many projects devolve into garbage because they are trying to shoehorn too much crap into reducer patterns when it just doesn't belong there.
- deleted 7y ago[deleted]
- imbusy111 7y agoHow do you update the front-end state after the backend task is complete other than reload the whole page?
- stillbourne 7y agowebsockets or any stream service such as kafka
- RedBeetDeadpool 7y agoI agree ... I recently went back to using Redux in a project and I'm loving it. Redux at its heart is just a state manager, but because people tie it to React I've gotten people tell me all sorts things about how you don't need it anymore with all its new features. I think the addition of React's hooks and context api actually make Redux easier to use, and I like the purity of its role as a state manager. I personally find that its cleaner to keep the overall application state in redux than to hold onto it inside of React, and leave react to manage its own component's state regarding ui level interactions.
- joekrill 7y agoRedux is great, and I'm glad to see all this cleared up, to some extent. Especially the bit about the new context API somehow eliminating the need for Redux. I know some people don't like redux and that's fine - don't use it. But it's still super-useful to many, many people.
- runawaybottle 7y agoWe all don’t get to waltz into a new job and say ‘Hey remove all this verbose Redux code and app structure, it’s slowing down velocity. Plus this crud app is too simple to add this annoying layer of boilerplate’.
- cameronfraser 7y agoI found I was just using Redux as a data caching layer and ended up using SWR hooks instead https://swr.now.sh/ https://swr.now.sh/. This has resulted in way less boilerplate (which increases even more with a type system) and a better development and user experience for the product I was working on. For everything else I use context like managing modals, auth, errors, and firebase connections.
- yatsyk 7y agoI can’t justify redux usage apart from legacy support. Mobx (preferred) or hooks for some apps/components.
- sktrdie 7y agoOne underrated thing that I miss from using Redux is the "action trace". You can literally sit down with the stakeholders [1] and explain the exact things that caused a screen to render. And these things are not cryptic function calls with stack-traces, but simple and chronologically ordered sets of human readable "actions" (I like to think of them as events) like UserFetched -> PlanFetched (<with this data>) -> FrozenUser. One can rewind the actions and iterate with the stakeholders why that screen appeared. This is huge and I miss this a lot. 1. Note that most of the time the stakeholder is yourself and/or another developer. But can also definitely be a non-coder.
- acemarke 7y agoIt's worth noting that the Redux DevTools Extension _can_ capture and display a literal stack trace for every dispatched action, if you've enabled that while setting up your store. This allows you to see what part of your app triggered each state update: https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/Features/Trace.md https://github.com/zalmoxisus/redux-devtools-extension/blob/...
- dprai 7y agohttps://cerebraljs.com/ https://cerebraljs.com/
- spex 7y agocerebraljs was superseded by https://overmindjs.org/ https://overmindjs.org/ according to the docs: https://cerebraljs.com/docs/advanced/typescript.html https://cerebraljs.com/docs/advanced/typescript.html it's also not clear how this is a replay to the above...
- PaulHoule 7y agoFour letters: V, U, E, X.
- jxub 7y agoOr MobX which is also neat.
- aerovistae 7y agoWorth noting this is from 2018...
- acemarke 7y agoAs I noted at the start of the post, I updated it literally yesterday with some additional information and links and then tweeted about it, which is why someone else apparently decided to submit it today.
- sergiotapia 7y agoThe most overrated tool I've ever had to misfortune of having to wrangle. Talk about bloat and lasagna code. I've used mobx and it's better. Now I use apollo, and it's even better. Just thinking about having to use redux and sagas and all that bloat makes my stress levels rise. I can't believe it became as big as it did. "muh time travel" is a meme of epic proportions.
- mosdl 7y agoAmazing how many downvotes all the redux critical posts get. Redux is indeed horrible and leads to all sorts of bloat and bugs.
- sergiotapia 7y agoSunk cost, these people have spent hundreds of hours learning something that ultimately is going to be discarded even more. That's why people are downvoting.
- lghh 7y agoNo, I downvoted because all the comments amount to X bad Y good. What they are posting has nothing to do with the article. The article even specifically talks about most of the Ys that are getting commented about and address what use-cases they are for that Redux isn't for. It's clear those people are not here to talk about the thing they are commenting on, they are just here to tell everyone they don't like Redux.
- mosdl 7y agoI have yet to be given a good usecase for Redux. All I see is code that ends up causing issues: - redux pollution (not cleaning up state and things leaking) - because you can't access redux state directly, components have to copy redux state and store them as props (which makes 0 sense, its state not props). But now you run into the issue where the local prop is not in sync with redux since redux updates are correctly done in chunks.
- izolate 7y agoI don't like how this article moves the goal posts of whether redux fits our use case or not. It has some valid arguments (dev tools) but the overhead of the boilerplate and tooling around redux is just not worth it IMO. Much better to break your app state into various custom hooks that leverage Context API and the `useReducer` hook.
- acemarke 7y agoNot sure what you mean by "moving the goalposts" here. I'm trying to make a few specific points: - Redux is not "dead" in the sense that it is still widely used and is continuing to be adopted - There are definitely many other tools in the React ecosystem that overlap with how you'd use Redux, but the Venn diagrams for the use cases don't entirely match up, and the other solutions don't necessarily have all the capabilities of Redux - Redux _has_ been over-used and put in apps where it didn't fit well, and I want people to only use it when it makes sense to do so - Our Redux Toolkit library and React-Redux hooks API make it a lot easier to use Redux
- runawaybottle 7y agoA lot of the pushback is coming from this: ‘ - Redux _has_ been over-used and put in apps where it didn't fit well, and I want people to only use it when it makes sense to do so’. ‘ There are developers working day in and day out in these Redux codebases so our feedback is coming from a real place. There’s a million articles that pushed Redux to the top and got it used in just about everything. Articles just like this one. This article is literally pushing back against all the reasons why Redux might not be a good fit. There’s very little in it that goes ‘yeah you know what, for this scenario, don’t use Redux’.
- acemarke 7y agoThat's because: - I have no control over the millions of other tutorials that have been written. I can only control my own blog, and the actual Redux docs. - The question of "When does it make sense to use Redux?" has been answered numerous times already [0] [1] [2] - I wasn't trying to address the "when?" question in this article. I was trying to answer "is Redux still a viable choice, and how does it compare to other alternatives?" I've written plenty of 6-10K word blog posts about Redux before that delve into how and when to use it. That wasn't my goal for this post. [0] https://medium.com/@dan_abramov/you-might-not-need-redux-be46360cf367 https://medium.com/@dan_abramov/you-might-not-need-redux-be4... [1] https://redux.js.org/faq/general#when-should-i-use-redux https://redux.js.org/faq/general#when-should-i-use-redux [2] https://blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao-of-redux-part-1/ https://blog.isquaredsoftware.com/2017/05/idiomatic-redux-ta...
- dprai 7y agohttps://cerebraljs.com/ https://cerebraljs.com/
- vikingcaffiene 7y agoI love Redux but I am very frugal about what I put into the store and have come up with a strong set of design patterns with my team to know what should and should not go there. That, in conjunction with hooks for any other stateful concerns we have, makes for a sane and pleasant dev experience. IMO the biggest and best draw of Redux is how it allows you to completely separate your business logic from your UI layers. Your components only know about props and state and are rather trivial to test. Hooks are great for re-usable logic as well but my team made the choice to have hooks deal only with localized state concerns and have a robust Actions => Services => Reducer layer for everything that speaks to things outside that constraint. Its worked out wonderfully so far. Tests are a breeze and logic is highly portable. Our UI layer is thin and easy to change. Its not all roses of course. The Redux store can turn into a rats nest of keys and values with no obvious structure (or worse, duplicated structures). It's something that requires actually sitting down and modelling out your data structures. Sadly that's something I don't see very often (and I am just as guilty as anyone else). The Redux team came up with some good guidelines on this point (too lazy to track the link down but its on the main site) and I think they have some really good ideas. I think more than anything its important to consider your store in the same manner you would a database and approach it with that kind of mindset. As with all things JS, its easy to dive in, hard to untangle yourself! :)
- acemarke 7y agoThat would be the "Style Guide" docs page: https://redux.js.org/style-guide/style-guide https://redux.js.org/style-guide/style-guide
- vikingcaffiene 7y agoThank you kind stranger :)
- tracker1 7y agoI do kind of violate this... I tend to use action creators that will accept an event from a component, and use e.target.dataset.someValue as necessary... it's not exactly a violation... but it's muddy... having clean action handler syntax in my Components though it better imho. I use createActionsHook below in every actions.js file... combined with thunks, it's awesome imho. https://www.npmjs.com/package/react-redux-actions-hook https://www.npmjs.com/package/react-redux-actions-hook
- tren-hard 7y ago> Is Redux dead, dying, deprecated, or about to be replaced? No. Reading through the comments it sounds like it's struggling, even positing the question sews doubt. I thought redux was still one of the 'must have' tools for building react apps now. What has everyone been migrating to? Is there a consensus successor to Redux?
- xwdv 7y agoNothing. The latest version of React has plenty of features now (such as hooks) that take the wind out of Redux’s sails.
- tmountain 7y agoIt depends on your use case, but he mentions some alternative solutions in the article. 1) React's Context API It's straightforward to use, and it solves the issue of passing data to deeply nested components, but that's all it does. 2) GraphQL Apollo Client I used this on a recent project for managing client-side state, and to me, it felt like I had to do a lot of work to achieve what should be basic functionality. It was my first foray with Apollo Client, so take my opinion with a grain of salt, but I found myself wishing I was using Redux instead for the duration of the project. Also, Apollo Client has some bugs related to cache invalidation (look on Github). These may be solved now, but they bit me pretty hard. 3) The new React "Hooks" API Looks nice. Have not used it.
- acemarke 7y agoThat's literally the point I'm making in the article. There's a huge difference between all the chatter on social media, and the actual stats reflecting Redux's usage. Two charts to illustrate this: First, overall downloads for React, Redux, React-Redux, MobX, and Apollo Client over the last two years: https://npm-stat.com/charts.html?package=react&package=redux&package=react-redux&package=mobx&package=apollo-client&from=2018-01-01&to=2020-04-04 https://npm-stat.com/charts.html?package=react&package=redux... You can see that net Redux usage overall has continued to increase, and is holding fairly steady at about 50% of React downloads. Second, for Redux Toolkit specifically, the growth rate from just before we released `redux-starter-kit@1.0`, then renamed it to `@reduxjs/toolkit@1.0.4`, through today: https://npm-stat.com/charts.html?package=%40reduxjs%2Ftoolkit&package=redux-starter-kit&from=2019-10-01&to=2020-04-09 https://npm-stat.com/charts.html?package=%40reduxjs%2Ftoolki... Obviously way fewer total downloads, but that's a steadily increasing growth rate for RTK. This is not something that's "struggling". There's just a lot of FUD thrown around on social media that makes it sound that way.
- abhisuri97 7y agoI taught a course on Javascript in undergrad with a unit on react as well as redux (cis.upenn.edu/~cis197, check it out!). To this day, I still think people learning JS should know about redux because of the design pattern it encourages (note that when people are first learning CS, this is probably the first-ish time they're coming across the concept of a reducer and "functional" state that isn't mutated directly). I think it's even more important for people self-learning react to be exposed to redux in some way; yeah, there's boilerplate, but it's just beautiful when all put together and isn't a Blackbox (I love dan's tutorial on egghead explaining redux from the ground up precisely because it breaks down exactly what's working and why it is). This blog post does an excellent job of convincing newcomers in the JS world to consider learning redux. I'm definitely forwarding this to the current instructor of the course!
- seeTheAstroturf 7y agoMaybe. I learned redux because I was told to. The official tutorial was outdated and it set me back weeks because I thought I was wrong. I suppose the structure was good to learn, my first concept of middleware and reducers.
- gbourne 7y agoI've used redux many times and the amount of boilerplate code is large. What Redux does is cool, but it complicates the app and is a pain to update. I feel this is going to go the way of Java Enterprise Beans as React continues to mature.
- rileytg 7y agoi propose updating the title to include something about this being (revised 04-2020) or [updated] i’ve been wondering the state of things as im jumping back into react projects after a couple years off.
- mharroun 7y agoRedux always had to much boilerplate for me to prefer it. The last couple years I have been using the new Context API and spliting my app state out by creating a global context, and many domain specific contexts where the context contains both the data and functions used to work with that data. Typescript + state with data and functions created a great api per domain. I found this approach just as clean but with less boilerplate. Though redux does have some performance and tooling benefits.
- tracker1 7y agoI disagree... I use useSelector, and now all my actions.js files export a default useActions method with a wrapper I wrote... Yeah, the boilerplate setting up the middleware and initial reducer isn't fun... but it's been really rewarding and the react-redux hook has been a godsend. https://www.npmjs.com/package/react-redux-actions-hook https://www.npmjs.com/package/react-redux-actions-hook
- acemarke 7y agoNote that with Redux Toolkit, that store setup is now a single line: const store = configureStore({reducer: rootReducer}) https://redux-toolkit.js.org/usage/usage-guide#simplifying-store-setup-with-configurestore https://redux-toolkit.js.org/usage/usage-guide#simplifying-s...
- tracker1 7y agoCool, but I tend to use sessionStorage as a backup to the store to re-hydrate on reload... I also use the thunks plugin so that I can have actioncreators that do multiple dispatches.
- acemarke 7y agoRight, and `configureStore` automatically adds the thunk middleware by default [0], as well as the Redux DevTools extension. You'd still have to pass in options for whatever persistence addon you want to use, but that would be something like: const store = configureStore({ reducer: rootReducer, middleware: [...getDefaultMiddleware(), myPersistenceMiddleware] }) Which is still shorter and easier to read than having to mess with `applyMiddleware` and `compose` yourself. [0] https://redux-toolkit.js.org/api/getDefaultMiddleware#included-default-middleware https://redux-toolkit.js.org/api/getDefaultMiddleware#includ...
- Justsignedup 7y agoSo many great things about redux that are hard to mimic... - the ability to create a middleware that is your analytics listeners. Analytics will listen to actions and spit out analytic info when those actions trigger. Because of this there is literally no analytics code anywhere in your codebase, except encapsulated in that one analytics middleware and sub-tree. - Ability to just see every state update in dev tools which is AMAZING for tracking down what caused a non-obvious problem. For example: Was it a bad api request? Was it a bug in the reducer? etc. Hard problems suddenly become easier with good debugging tools. - Ability to persist a part of the store to local storage. This is actually quite nice.
- karatestomp 7y agoOne thing I like is that it's really easy to put a client library (for, say, some REST service) behind a combine-reducerable Redux store and a few exposed "action creators" (event emitters). Especially if you're using TypeScript so all that stuff's easy to find and understand. Anyone familiar with Redux will be able to use it immediately, and it'll work just fine anywhere JavaScript does (provided whatever other packages the client lib depends on will work on a given platform) including places you might want, for good reasons, to use JavaScript but lean on some UI system other than React (Apple TV, say, or maybe Electron).
- daenz 7y agoThat quote "if you're explaining, you're losing" applies here.
- acemarke 7y agoTrying to clarify FUD on the internet is certainly a fool's errand, but at least I've got a writeup to link to when I see people ask these questions.
- ChrisArchitect 7y agoprevious comments, when this may have actually been news: https://news.ycombinator.com/item?id=16918003 https://news.ycombinator.com/item?id=16918003 why post it again?
- acemarke 7y agoI updated the post yesterday with new links and information, and tweeted a mention of having done that. Apparently someone thought it was worth submitting. (tbh I'd forgotten it actually hit the front of HN when I wrote it the first time!)
- markandrewj 7y agoI find the hook API cleaner for most common use cases. It is also better for things like forms, which redux wasn't intended for. https://redux.js.org/faq/organizing-state#should-i-put-form-state-or-other-ui-state-in-my-store https://redux.js.org/faq/organizing-state#should-i-put-form-...
- techsin101 7y agoI like redux but what could be achieved with an a tag and another HTML page now needs 700 lines of code due too react, redux, webpack, router, server rendering, partial loading................................................. Yeah I don't want to make my life harder for no reason