Full disclosure, I am not fan of Hooks. They seem to abstract away a part of Component Lifecycles that never needed to be abstracted. Checkout out this article: https://codewithghazi.com/componentwillunmount-with-react-hooks/
Instead of componentDidMount and componentWillUnmount, Hooks makes us use the cryptic useEffect:
useEffect(() => {
document.addEventListener('click', handleClick);
return function cleanup () {
document.removeEventListener('click', handleClick);
}
}, [])
I understand using Hooks for simple functional components that require some small uses of state. But once we get into lifecycle methods and about half a dozen state fields, I find that hooks actually get in the way.
I really like code that explains what it does. I prefer setNameOnClick as opposed to handleClick (unless I'm making a reusable Component).
I like state that is easily identifiable. this.state.userName is clearer to me than userName.
Overall, Hooks to me seem like they make code more "code-y" and I know I want a coworker to be able to understand my work ASAP.
Thoughts?
Top comments (1)
Both articles uses
useEffectfor their example, what about others and the idea at all ?'and about half a dozen state fields' - if you mean, u need to use
useStatefor every state variable, you can do that:const [state, setState] = useState({/*default state object here */ });