DEV Community

Tamb
Tamb

Posted on • Edited 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?

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

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

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️