All it's good for is for adding unnecessary complexity and satisfying your mid-level developer urge for bloated code that feels clean for some reason, cuz you just don't know better.
useReducer adds complexity and doesn't yield any benefits.
You see, the complexity of a code base is directly correlated to the number of interfaces it exposes. So like the number of things it can do, the number of functions, helper functions, classes, uh, components that it has. So the number of things that are concepts within this, code base is what Dr.
Ousterhout in, in the book refers to as the number of interfaces. So when you decide to use, use reducer, your component no longer has a simple, powerful interface into its own state. Instead, you have two interfaces. You have the components state shape itself and and, and set state, which is the interface into it, and then a made up reducer interface that you created where you invented a bunch of little magic words like success or whatever.
So that in turn, results in. Another problem described in the book have philosophy software design, which is called change amplification. So when you need to add more functionality, you'll typically have to modify three places instead of two. Not always, but typically, instead of modifying just the component state shape and the set state call, To invoke that state shape or call or calls, you're gonna need to modify the component, state shape, the reducer call, and then the reducer itself.
Change amplification is very, very bad, and it's what makes code bases difficult to, maintain and prone to bugs. At a foundational level what useReducer doing is introducing a flawed decoupling, which in turn hurts cohesion. Cohesion is a concept of software engineering that refers to the the property of different parts of the same bit of functionality should be close together. The less cohesion a bit of functionality has, the harder it's to reason about the harder it's to follow the code, the harder it is to maintain it. If you use use reducer, you're lowering your cohesion, and if you are lowering your cohesion, you better be getting something really good out of it.
Like an example is code reuse or performance. Code reuse is the most common and important and valid reason to reduce cohesion. But useReducer lowers your cohesion and gives you nothing in return.
Let me know what you think. If I'm an idiot or if I'm right. If you agree, disagree, let me know in the comments. If you have a good argument for user reducer doing something that I'm not aware about, I'll be happy to learn.
Информация по комментариям в разработке