DEV Community

Discussion on: React Is Eating Itself

Collapse
 
louiszen profile image
Louiszen • Edited

Just a syntax perference.
Many hook programmers have many wrong basic concepts:
1) Adding the keyword "function" will become functional programming, while adding the keyword "class" is OOP. (In fact, they are not exactly the opposite, but much closer to the concept of how you organize your procedures. In fact, I taught my students they should have a mind set of both FP and OOP, best coding needs FP's stateless procedure isolation and OOP's code hierarchical organization)
2) Hook shorten codes, so they can add TypeScript to that.
(Hook are somehow contradict to the concept of TypeScript, hook wants to bypass framework restriction, while typescript is adding restrictions on variable type)
3) Static classes are evil, all non-rendering things should be in Hooks.
(I think they regard React as a language more than JS)
4) Misunderstanding the behavior of the followings: (function pointer and execution of functions)...
func
func()
() => func
() => func()
() => {func()}
because useState in fact is something like this I guess? they implicitly execute the function pointer in useState.
useState = (val) => {
this.v = val;
return [
this.v,
(v) => {
this.v = _.isFunction(v)? v(this.v) : v;
}
];
}
5) Hooks can shorten class!... (but in fact the main working code cannot be simplified, and boiler plate still exists, why not use a code template generator?)
6) Tends to build small unorganized things with high coupling because they like to make every function component stateful
7) Keep saying that hook improve the performance (but in fact not)
8) Keep saying that hook can minimize bugs, (but they even dont know when the function is executed)

Hook can be easily translated to Class, but not every class can translated to Hook.
I wonder who invents hook is come from the decades of ES5?
The coding style of hook I can find them appearing in most of the buggy systems which is full of callback hell in the days of ES5.
Everyone knows that class is just a syntax sugar in ES6, the undereath is still a function.
Just like async/await, a group of people still insist to write callback hells.

I do think that every syntax have their beauty and someone can code Hooks in a nice way.
But I cant meet one, most of them having that ability will go for class.