Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I largely came to the same conclusion, including going back to Redux. I have found using Apollo for client side state very cumbersome and even difficult. You really do need to understand their cache well, and I also dislike having to deal with things like __typename, which I feel is an implementation detail that unfortunately gets foisted onto the end developer. Sometimes __typename is a royal pain in the butt.

The article touches upon current Redux as well, such as when it says "If done right, it can definitely be a breeze to work with", which I agree with. And the "if done right" part has gotten a lot easier, as Redux has finally decided it's ok to provide opinionated approaches that guide you towards that happy path. I really do think if Redux hadn't been so concerned about being opinionated way back when, it'd be far better received today. But better late than never.




I think the biggest problem is the default approach of using thunks for handling async state. You get these "opinionated" frameworks that then reinforce terrible design ideas.

If it's simple just put handle async stuff in situ. If it's more complex, use custom middleware. Thunks, sagas, etc are all anti-patterns. The single worst thing the Redux docs did was give the impression that middleware was some kind of advanced functionality only useful for library designers. Most of your app logic should probably live in middleware.

The "redux toolkit" or whatever doesn't help with that, it only reifies questionable practices. Skip it. Write a simple utility for generating actions/types, and then go about your business.


I'll have to disagree with that, on multiple levels.

Thunks are simply an approach for writing reusable async logic that has access to `dispatch` and `getState`, without being tied to a specific store [0]. While I do think more people would benefit from writing middleware for their own particular use cases, most people just want to have a place where they can fetch some data and dispatch an action containing the result. Thunks make that straightforward. Thunks are also by far the most widely used async middleware across the Redux ecosystem. These are all reasons why we settled on thunks as the default async middleware included in RTK [1]. (It is worth noting that with the advent of `useDispatch` and hooks, you can write some fetching logic directly in a `useEffect` call vs a thunk, but there's still benefits to using thunks in many cases.)

RTK has specific support for thunks in two ways. `configureStore` automatically adds the thunk middleware to the store setup [2], and we have a `createAsyncThunk` API [3] that handles the common pattern of dispatching actions based on the results of a promise.

However, nothing about that requires that you use thunks with RTK. You can still add whatever middleware you want to the store, whether it be sagas, observables, custom middleware, or something else.

> The "redux toolkit" or whatever doesn't help with that, it only reifies questionable practices. Skip it. Write a simple utility for generating actions/types, and then go about your business.

I'm afraid this is entirely wrong.

RTK encodes the best practices recommended in our Style Guide docs page [4], and includes APIs that simplify your Redux logic considerably:

RTK improves your Redux code in many ways:

- `configureStore` lets you set up a Redux store in one line with good defaults built in, including automatically adding the Redux-Thunk middleware, enabling the Redux DevTools Extension, and warning about accidental mutations

- `createSlice` generates action creators and action types for you automatically - all you have to do is write reducers and given them reasonably descriptive names. In addition, it uses Immer internally to let you write "mutating" reducer logic that is safely turned into correct immutable updates, so no more nested spread operators.

- As mentioned, `createAsyncThunk` handles the typical use case of dispatching actions before and after making an async request - just fetch your data and return a promise, and it'll dispatch actions automatically.

- `createEntityAdapter` provides prebuilt reducer logic for typical collection management operations, like `upsertMany`, `addOne`, `removeAll`, etc.

So, RTK _is_ that "simple utility for generating actions", and more. It's an official package from the Redux team (ie, myself and the other maintainers), you can pick and choose which of its APIs you actually use in your app, and you can mix and match which parts of your Redux logic are written with RTK with parts that might still be written with other approaches.

[0] https://blog.isquaredsoftware.com/presentations/workshops/re...

[1] https://blog.isquaredsoftware.com/2020/02/blogged-answers-wh...

[2] https://redux-toolkit.js.org/api/configureStore

[3] https://redux-toolkit.js.org/api/createAsyncThunk

[4] https://redux.js.org/style-guide/style-guide


What's with the copy paste spam on every one of your posts?

None of what you're saying matters in the scheme of things. You can get everything you need from

    const { types, actions } = createActions([ 'ACTION_NAME', ...]);
Where createActions is an exercise for the reader, but shouldn't take more than a few lines. Then go about your business from there. Adding another layer of framework over the top of this stuff only obscures what's going on under the covers.

The middleware approach is more straightforward than thunks and far more maintainable. Reifying that as "best practice" is only going to continue to spread this anti-pattern because no real application is about "just grabbing some data for a bit" and inevitably that one api call expands into many, not to mention all of the other side effect related and asynchronous functionality that one has to deal with in user interfaces.


He's been doing it for a while now. I believe he has setup some google alerts on the words 'redux | thunks | sagas' and he just brings his redux toolkit gospel along. And not just on this site, like, everywhere. Dev.to, reddit, twitter...

I've confronted him once but to no avail, I even got downvoted by the community. :)

https://www.reddit.com/r/reactjs/comments/fvuwpl/handling_si...

edit: i see that's happening to you too here lol, godspeed


They are one of the maintainers of Redux Toolkit (which has made Redux so much nicer to work with)


Honestly, the only alert I have is a Tweetdeck search for hashtag `#redux`.

Other than that, I just spend too much time on social media :)


I would shorten the copy to be more effective.


Haha yeah. Evangelists, man. Ah well, what can you do.


Or, with `createSlice`, you get the action creators for free with your reducers:

    const todosSlice = createSlice({
      name: 'todos',
      initialState: [],
      reducers: {
        addTodo(state, action) {
          const { id, text } = action.payload
          state.push({ id, text, completed: false })
        },
        toggleTodo(state, action) {
          const todo = state.find(todo => todo.id === action.payload)
          if (todo) {
            todo.completed = !todo.completed
          }
        }
      }
    })

    export const { addTodo, toggleTodo } = todosSlice.actions

    export default todosSlice.reducer
You're welcome to your own opinion, but we've designed RTK based on how we've seen the community use Redux, and built it to solve the problems they're dealing with.


I see what you’re doing there. I also see why you think it’s a good idea. "How the community" uses redux is badly. I guess congrats for reinforcing that at scale. Gives me some more hours to bill when I run across the next ratsnest.


Can you provide some examples of a better way to use redux? The react and redux toolchain is so flexible I'm always interested to see what ways other people come up with to use it.


I have a copy paste dump that I did a few months back to show someone how I was working, happy to pass that along. I wouldn't make claims that the way I'm using things are the best but so far I've been happy with the general approach. There's a simple createActions and a more complex one that handles namespacing.

https://gist.github.com/weeksie/04f41329d0015e2128209df9f9de...

I skimmed the debounce middleware from this guy Nir Kaufman who has some pretty good things to say about front end architecture. Generally with Redux we have a system that can absolutely provide real event-driven CQRS style front end so it seems crazy to ignore that in favor of managing async thunks like it's 2004 and we've all just discovered how to put an XMLHTTPRequest on an onclick handler or something.

Outside of that core.effects file, I put all of the async app logic in custom middleware as well. YMMV but using a framework for replacing const declarations and switch statements is overkill.

The broader point is that if you're going to create utilities like that, it's often worth just rolling your own. When you attach a core part of your application to a framework you've signed up for the ride. I realize it seems like I'm being an asshole to acemarke, who appears to be a perfectly lovely dude, if a little passive-aggressive, but I sincerely feel like pushing libraries for problems that shouldn't require libraries is making our ecosystem worse.


Like when you send data to a mutation and it complains about it having a __typename field that they bloody added. Had some pain with that this week.


> I really do think if Redux hadn't been so concerned about being opinionated way back when, it'd be far better received today

Can you clarify what you mean here?

From my perspective as a Redux maintainer, most of the concerns I've seen expressed about Redux over the last few years really didn't focus on whether it was "opinionated" or not. It's been a combination of:

- Not understanding the original intent behind Redux's design and the historical context that led to it being designed that way [0]

- People being told they _had_ to use Redux with React, even when it really wasn't a good fit for their use case

- The "incidental complexity" of common Redux usage patterns [1], most of which were due to the way the docs and tutorials showed things (writing `const ADD_TODO = "ADD_TODO"`, separate files for actions/constants/reducers, etc).

- Changes in the ecosystem leading to other tools whose use cases overlapped with why you might have chosen to use Redux previously

All that said, yeah, we've made a concerted effort in the last year or so to be much more opinionated about how you _ought_ to use Redux, based on how we've seen people use it. Those opinions are built into our new official Redux Toolkit package [0], which is now our recommended approach for writing Redux logic, and the Redux Style Guide docs page [1], which lists our guidance on best practices and patterns for using Redux.

I also just published a brand-new "Redux Essentials" core docs tutorial [2], which teaches "how to use Redux, the right way", using our latest recommended tools and practices like Redux Toolkit and the React-Redux hooks API.

We unfortunately can't wave a magic wand and get folks to update the seemingly endless parade of Medium tutorials and Youtube videos that show the older approaches to using Redux, but I'm hopeful that the emphasis on using RTK will make it a lot easier for folks to learn and use Redux going forward.

[0] https://blog.isquaredsoftware.com/2017/05/idiomatic-redux-ta...

[1] https://blog.isquaredsoftware.com/2019/10/redux-starter-kit-...

[2] https://redux-toolkit.js.org

[3] https://redux.js.org/style-guide/style-guide

[4] https://redux.js.org/tutorials/essentials/part-1-overview-co...


You certainly have more experience and context than me. But my experience with Redux over the years is there was so many ways to do it leading to a lot of uncertainty. Do you use a switch statement or something like redux-actions? Do you use the duck pattern, where do all these things live in the codebase? What package do you grab for async actions? Are actions 1:1 with DOM events, or are they more like a state machine? How do you compose reducers? Should you compose reducers?

I think this led to a lot of confusion and uncertainty with Redux. "I'm using it, but I'm not sure I'm using it effectively." I think a lot of ineffective implementations caused a lot of developers to get a really bad taste. I can unfortunately say at my previous company, just mentioning Redux would make just about every developer cringe. I hated that.

But I feel like a lot of what is making Redux more successful these days is the more opinionated releases like the toolkit and the new docs. Since they've only been around about a year now, I think it's reasonable to conclude that before their existence, Redux didn't have a strong opinion a new developer could lean on.

It's similar to React, which also tries to avoid opinions. I can appreciate and understand that approach (for both React and Redux), but I do wonder would React be better if there was a stronger opinion on things like CSS, routing, state, etc?

I don't mean to criticize. I love Redux and am very grateful for it. This is just how I experienced it over the years.


Redux was reasonably clear and opinionated early on.

People on whom it was forced on, and who disagreed with those opinions, were VERY vocal, and pushed most of the other crap, which fragmented the community and muddied the message.

From my point of view as a end user, the only real difference between now and then, is that the vocal minority is now the majority, and they shifted focus to match (which is a good decision). Obviously I can't speak for Mark, but it's how it looks like as an external observer (pun not intended)


Having used Redux for some elaborate stuff (in particular, a web app that used a couple of KB of info in Redux to generate an extremely dynamic UI, with diff-style data changes via Websockets inserted in realtime), honestly, the biggest problem I've seen with Redux use is just... people using it for things when they shouldn't.

This is most glaring for the whole "do a GET and store it in Redux" thing, where if there's no actual data mutation or derived data or anything else that actually requires or makes use of a global scope, you should just be using a memoized API call function (or a library that abstracts away the common use cases of one, like SWR).


> people using it for things when they shouldn't

I know people that advocate putting everything in redux. They are quite serious about this. Then you end up with reselect everywhere and the whole goddamn universe is memoized. No one seems to know how React renders (or re-renders), so memoize everything! Yes! That's the ticket.

The overuse of Redux and the React hook brain damage stems from the tide finally turning against OOP. Haskell did a number on the OOP paradigm. So everyone is afraid of encapsulated state and localized logic. Then you end up with React hooks. Instead of making React's object API better, they choose to make functions worse. So everyone is pretending they are doing functional programming when in reality they are just using functions that are bastardized with this weird flavor of dynamic scoping and all the subtleties of that. But I digress.

Today, there are a thousand different ways to do web development wrong and practically no way to do it right. Starting with misconfiguring webpack and working up the stack. It's a true complexity quagmire. But surely there is a SaaS or open source toolkit (with adjacent commercial services!) coming soon to help guide us out of the fog.

Just kidding. This hell of ours is by design.


> Instead of making React's object API better, they choose to make functions worse.

I'd be really curious to see how you'd make the object API reusably composable, given that that's one of the basic reasons for hooks existing as they do.


An over emphasis on re-use is what ruined a lot of oop systems also. Maximise reuse, minimise use. It's a trade-off.


I pretty much totally agree. FWIW, I do think there might be some good things on the horizon. Rome has a lot of potential, as do Remix and Svelte. We'll get past this :)


So what would be your guesstimate on the percentage of redux uses in the wild that are unnecessary and just introduce complexity or boilerplate instead of providing a benefit?


FWIW, my current estimates are that roughly 50% of all React apps use Redux.

I'm gonna go out on a limb and guess that maybe 1/3 of those Redux-using apps probably aren't really benefiting from Redux (things like using it _just_ to avoid prop-drilling when you could just use Context, writing reducers that are nothing more than `return action.payload` with no real logic, etc).

We've always had an entry in our FAQ section that gives some advice for when it might make sense to put a particular piece of state into Redux vs keeping it in component state. As I rewrite the Redux docs piece by piece, I'm trying to add some additional clarification and emphasis on when you should actually consider using Redux overall.


I certainly get where you're coming from, and agree that all of the questions you listed are things we didn't express opinions on previously and had to decide for yourself.

Still, the bulk of the concerns I've seen over time fall into the categories I've listed - I just really don't remember seeing many comments from folks who were concerned that they "weren't using it effectively" as a particular pain point. Perhaps that was being felt, but expressed in different ways? (I definitely think a lot of people _haven't_ been using it effectively, but didn't necessarily realize it.)

In any case, the highly positive response to RTK and the docs work tells me we're headed in the right direction.

My next task is to rewrite the existing low-level "Basics/Advanced" tutorial sequence to remove outdated references, show simpler patterns, and improve explanations. I've got my notes on things I want to change here:

https://github.com/reduxjs/redux/issues/3855

If you or anyone else has any particular feedback on things you don't like with that existing tutorial or would like to see covered better, please comment and let me know!


Man I wish you’d quit spamming every redux thread with this stuff.

You’re not solving any problems, you’re just promoting your framework.


I don't think this comment is fair - acemarke does show up in virtually every Redux discussion on HN, but I've found his comments to be reasonable and helpful. I don't think labeling them as spam is justified.

He makes an effort to address specific points, doesn't get defensive or angry, and seems to take criticism and feedback seriously. He has responded to my own critiques of Redux in a reasoned way.

I think that if someone is going to express claims or opinions about a library on HN then we should be happy to see an expert response, rather than letting the discussion become one-sided. Sure, there could be a bias, but I think we all win by having both sides represented.

Do we really want to discourage that?


I see it as someone clout-chasing for their framework. A framework that promotes questionable practices. Framework developers and working engineers have diverging interests.

The problem with his style is that he parades himself as an expert but he's emphatically not an expert. He's a guy with an agenda to push his open source framework. I understand where the bias toward politeness comes from, but that makes groups like HN susceptible to this kind of pretense to authority. He's actively making working developers' lives worse by promoting this stuff and it's frustrating.

Perhaps I shouldn't give a shit.


> The problem with his style is that he parades himself as an expert but he's emphatically not an expert

Erm... I've been a Redux maintainer since mid-2016. I oversaw development of React-Redux v5 and v6, wrote v7 by myself, and directed development of the hooks API in v7.1 over the course of multiple 250+-comment issue threads.

I've written the Redux FAQ, "Structuring Reducers" usage guide, the "Style Guide" best practices page, almost all of the Redux Toolkit docs, and the new 25K-word "Redux Essentials" real-world tutorial.

I've written about 150K words of Redux-related blog posts, including tutorials, history, technical architecture, and best practices.

I've given multiple conference talks on how Redux works and how to use it.

Even if you don't agree with the approaches I'm recommending that folks use...

if _I_ don't qualify as an "expert" on this topic, who _does_? :)

If you have actual substantive technical arguments for other approaches we should be recommending, please feel free to open up an issue to discuss them. I'm genuinely always interested in ways we can make it easier for people to learn and use Redux.


Lots of blog posts, tutorials, etc. blah blah blah.

How many complicated applications have you built with Redux at their center? Because that's the part that's missing from your list of qualifiers for being an expert.


Two, because I've spent the last 9+ years of my career working on the same couple apps :)

But both were pretty complex - true SPAs, no routing, lots of complex client-side state manipulation going on.

In fact, the first one is actually what inspired everything that I showed in my "Practical Redux" blog tutorial series, since I couldn't show off work stuff publicly.

But hey, if that list of stuff I've done isn't good enough for you, apparently no one in this world qualifies as an "expert" in any topic :)


You've worked on two apps. Besides that you've been a part of the evangelist ecosystem for a tremendously simple framework. You are not what I could call an expert in using Redux.

You are almost certainly an expert in Redux's internals but that's not what we're discussing. In fact the root of the problem is exactly that you've conflated one for the other.


I know I'm feeding a troll here, so last response.

I've looked at hundreds of other codebases, ranging from beginner apps to complex enterprise-level apps. I've talked to thousands of people who are using Redux in many, _many_ different ways, and catalogued hundreds of libraries people have made to add on to Redux. I _know_ how people are using Redux in practice, and what kinds of problems they're running into.

I'm quite serious when I say I'd like you to write up an issue with some specific concrete feedback listing your concerns with how we currently teach Redux and recommend people use it, especially since I'm working on an ongoing revamp of our core docs. I obviously can't guarantee any _changes_, but I'm very interested in having substantive discussions in a more suitable venue than HN comments.

Whether or not you choose to take me up on that is up to you.


I'm not trolling you, I'm exhorting you to stop pushing extra frameworks for things that there should not be frameworks for.

The issue is not that one or another approach is always better, it's that the entire act of lobbing another framework onto the stack that a dev has to familiarize themselves with only adds to the confusion.

Rails worked because it contained everything in one package. The success of that model poisoned everybody's mind into believing there had to be "opinionated" frameworks to manage other (extremely simple) frameworks and has contributed greatly to the mire of misdirection that is modern front end development.

It's a case of not even wrong.


Simplify. Less is more.


The guy just likes to larp as a writer, so it’s not a surprise that he’s loving the discourse. Just ignore him —- He’s massively coping for his front-end shortcomings.


If you gave actual technical arguments instead of just attacking the credentials of a person you'd actually contribute to the discussion at hand. As is, you seem to have a pretty bad day …


> Framework developers and working engineers have diverging interests

how is that?


Framework developers want you to use their framework. Engineers want to solve a problem in a manner that works best for their organization. The two incentives sometimes intersect but that is by no means a given.


A framework tends to want to capture or serve all possible use cases, while app developers want to serve a single, specific use case.


Bitterness: The Comment.

You can write a short story about this on your blog, now that you’re a “full-time writer”.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: