DEV Community


Discussion on: Redux is half of a pattern (1/2)

salvoravida profile image
Salvatore Ravidà

The power of Redux is its low level api, and middleware support.

We have to assist every days to tons of common places about Redux.

Thread Thread
davidkpiano profile image
David K. 🎹 Author

The low-level API is fine... that it enforces a single atomic global store is where unnecessary complexity grows.

More on that in part 2!

Thread Thread
salvoravida profile image
Salvatore Ravidà • Edited

You are missing the point, that "reducers" and "combineReducers" are de-facto the way of split a "global Store" into many "subStores" but with theese advg:

1) every "subStores" can listen every action/event and so react to that if needed
2) you have a centralized way to debug/control your app via DevTools.
3) you can access/interact with state outside of rendering lib-> think to channels, inter-framework communication - etc...

You can understand/debug all-business-logic of an "well-projected-redux-state" app, in few minutes, just opening Redux DevTools.

Moreover you can use As many Stores as you want, just as people use as many "React.Context" by using many <Provider !

The main advantage is to have 1 SINGLE "ROOT" of THRUTH!

Note "Root" not single Store.

That Said,
Decoupling business logic from render is something that every software architect should think about. Today react is the best rendering lib, but nobody knows tomorrow.

Redux and middlewares is perfect to Decoupling business logic from rendering.


Just as Generics, tomorrow just change "React".

Thread Thread
davidkpiano profile image
David K. 🎹 Author

Okay, please keep using Redux however you'd like, thank you for your comments

Thread Thread
bradtaniguchi profile image

I do find it fascinating how there are very drastic responses to this post so far I must say. Some people agree that Redux is inherently "wrong", and other argue its inherently "right".

I'm like many, waiting for part two :D

Thread Thread
blocka profile image
Avi Block

The main advantage is to have 1 SINGLE "ROOT" of THRUTH!

Not sure about you, but in the types of apps that I write, I can not see any advantages of having a "single source of truth". In general, the complexity is always either at the page level, not the app level (the app is essentially just a router with some small global data, and an entity cache), or within some sub components on each page.

So I don't need a "single state atom" for anything. What I do need is to manage the state transitions of those complex components. Redux does nothing for me here. XState does tons.

I suspect most people are using redux as a global entity cache, or worse...what you do to store "global" data.

Thread Thread
luiz0x29a profile image
Real AI

They talk about Single root of "thruth", but the elephant in the room is the insidious internal mutable state on every React component that's not pure and/or has hooks.

Wasn't the entire point of modelling state/events/transitions knowing when to do actions, like rendering the screen.

So if there was a proper way of doing virtual finite state machines, you wouldn't need react to reconcile the three, you could just go and change the DOM directly with impunity.

The DOM would be the single source of truth for the visual representation of the applications, and it wouldn't be slow because you wouldn't be randomly poking and mutating it without reason.
It would actually be faster, as it would only change precisely in "reaction" to state+events, ironic for something called "React" that doesn't react to anything, it should be called Render.