What’s The Deal With React Hooks?

What Are Hooks?

The official React docs define hooks like this, “They let you use state and other React features without writing a class.” This is a very simple definition, but it really does say it all and speaks to the simplicity of implementing hooks, which is one of the best parts about them. We no longer need to write class components, and/or deal with everything that came along with class components. There no longer have to be different types of components that are siloed to do different things. State and data management becomes much smoother and simpler.

How To Implement Hooks?

Implementing hooks is very simple. First you can just define a basic functional component.

How I Used Hooks In My Project

When I started my project I knew that I wanted to have as clean and modern React code as possible. I was determined to not use any class components and implement anything I would have needed a class component for, with hooks. Here’s an example of part of one of my components, a create form:

Final Thoughts

Building this project was really my first exposure to using React Hooks. I had heard about it before, but hadn’t actually worked with them myself. I think they’re amazing. I enjoyed using hooks much more than writing class components, worrying about where I can use local state and where I can’t. Thinking about all the props I need to pass down, what callbacks I need to pass from this component to that component. It just all feels much more straightforward to me to use hooks. I also felt it made using Redux easier as well, and I know for newer developers Redux can be something that can be really challenging. Every little bit helps.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store