DEV Community

Tamb
Tamb

Posted on • Updated on

Are React Hooks Actually Worth Using?

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);
   }
}, [])
Enter fullscreen mode Exit fullscreen mode

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)

Collapse
 
vladi160 profile image
vladi160

Both articles uses useEffect for their example, what about others and the idea at all ?

'and about half a dozen state fields' - if you mean, u need to use useState for every state variable, you can do that:

const [state, setState] = useState({/*default state object here */ });