DEV Community

Jayant Khandelwal
Jayant Khandelwal

Posted on • Edited on

Why should we use React Hooks?

What are the hooks?
Hooks are a new feature in React >= 16.8 which allows you to use React features without having to write class components.

Uses of Hooks:
1.) Allows you to use React Feature without writing a class.
2.) Avoid the confusion by 'this' keyword
3.) Allows you to reuse stateful logic
4.) Allows you to organize the logic inside the component into reusable isolated units.

Rules to use Hooks:

Rule1: "Always call hooks on the top level."
Do not call hooks in the loops, conditions, and at the
nested functions

Rule2: "Always call hooks from the React functions."
Do not call hooks from any regular JavaScript components
but rather always call it from React Functional components.

Happy Coding!
- Jayant Khandelwal

Buy Me A Coffee

Top comments (3)

Collapse
 
ahmedhalim2290 profile image
ahmed Abd El-Halim

there is any sample project to understand the deference between Class and Hooks

Collapse
 
jackent2b profile image
Jayant Khandelwal

I will soon be making a complete series on Hooks!
And will talk about the difference between hooks and Class as well!
Stay Updated, Cheers

Collapse
 
ahmedhalim2290 profile image
ahmed Abd El-Halim

thanks brother I'm waiting you