|
|
|
|
|
by valenterry
2017 days ago
|
|
I'm not familiar with react hooks, but when I read what you write, my immediate reaction is: we already have a way to reuse business logic. It's called functions. Define a function and use it, either a global static function or pass it down to the component if you want to mock it. Reading the react docs, I find this part interesting: > Hooks were designed with static typing in mind. Because they’re functions, they are easier to type correctly than patterns like higher-order components. Importantly, custom Hooks give you the power to constrain React API if you’d like to type them more strictly in some way. React gives you the primitives, but you can combine them in different ways than what we provide out of the box. (https://reactjs.org/docs/hooks-faq.html#do-hooks-work-with-s...) Seems to me as if hooks try to fix the lack of a good programming language. These approaches usually go wrong eventually. Maybe it's time to ditch Javascript (and even Typescript) and use a proper language (purescript maybe?) so that all these things can be done with just functions. |
|
Hooks are functions. If that wasn't obvious, it's also explicit called out as a key thing about them in the excerpt from the docs that you present and then try to make a point with that entirely ignores the content of the excerpt.