DEV Community

Aditya Rawas
Aditya Rawas

Posted on • Updated on

What is React hooks ?

Hooks where added in React version 16.8 which allows you to use React without having to write a class.
Ex. State of a component.

In react version <16.8 you can only use states only within class components. With hooks you can use states in other react features without writing a class.

Keep in mind that hooks don't work inside classes

Hooks are the function that hooks into React state and lifecycle features from function components

Rules to use Hooks.

  • Can be called only on top level. Never call hooks inside any condition, loops if nested functions
  • Only use it in React functions Hooks can be called either from custom hooks of from React function components

Aditya Rawas Coffee

Top comments (0)