Skip to main content

Command Palette

Search for a command to run...

What is React Hooks ?

It's a special function that allows us to hook(use) into the react features and state without writing a class.

Updated
•1 min read•View as Markdown
What is React Hooks ?
K

I am passionate about creating seamless web experiences with modern technologies. My unwavering commitment to staying at the forefront of the industry is fueled by a goal for continuous learning and professional development.

To keep it simple. It's a special function that allows us to hook(use) into the react features and state without writing a class. Which was prominent before the introduction of hooks. Hooks was integrated as the new addition in react 16.8V.

Hooks allows us to reuse the stateful logic in particular without changing the component hierarchy. A state is the current data(information) or properties of the component that needs to be tracked/recorded.

In order to use hooks, firstly we need to import particular hooks from the react. As in the picture we imported useState hook from the react. We are going to learn about our first hook namely useState hook in the next article. hook usestate.png

There are fundamental rules to use the react hooks.

  • Hooks can only be called inside react function component.

  • Use hook only at the top level of the functional component before it returns.

  • Don't conditionalize the hooks. Simply! hooks cannot be conditional.