2 ms·
To be fair hooks are kind of a frivolous feature that add no new functionality (just another way to do something we already could). It does irk me a bit when li
by viklove 7y ago
To be fair hooks are kind of a frivolous feature that add no new functionality (just another way to do something we already could). It does irk me a bit when library maintainers do stuff like this because it just introduces more complexity and more patterns into a framework that people feel the need to tap into. Smart devs will just opt not to use hooks, but it sucks that the industry will likely adopt it for no reason other than keeping up with the latest trends.
React peaked at v16.
- baron816 7y ago> Smart devs will just opt not to use hooks Couldn’t disagree with you more here. Smart devs use smart abstractions. Hooks is a smart abstraction because 1) classes and inheritance don’t belong in JS, 2) they allow for more code reuse, 3) they allow you to write simpler, more declarative code.
- viklove 7y ago> 1) classes and inheritance don’t belong in JS You gonna back this claim up? Because it doesn't stand on its own. Inheritance certainly doesn't gel with _React_ (use composition), but to say it doesn't belong in JS is rather naive. > 2) they allow for more code reuse You can already get just as much reuse out of React's context API > 3) they allow you to write simpler, more declarative code. This is rather subjective, but I'd argue it's not simpler, because it "hides" the state with internal magic, and it's not even more declarative because using a context (or composition) based approach would be just as declarative. I'd actually argue it's far more complex, because each invocation of `useEffect` doesn't even have the same result! There's some behind-the-scenes magic going on that makes it harder to reason about and find bugs. The nice thing about having classes is that it's very easy to understand what code runs when a component is initialized (constructor and componentDidMount) versus what code is run on each render cycle (the render method). Hooks just removes that whole distinction and throws everything into one place. Devs who are new to React will definitely struggle with understanding what is going on behind the scenes.