Are React Hooks Actually Worth Using?
Tamb

Tamb @tamb

About: I am not the brightest tool in the shed

Location:
Pittsburgh, PA
Joined:
Mar 18, 2019

Are React Hooks Actually Worth Using?

Publish Date: Feb 16 '21
0 1

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?

Comments 1 total

  • vladi160
    vladi160Feb 17, 2021

    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 */ });

Add comment