DEV Community

Aditya Rawas
Aditya Rawas

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay