DEV Community

Discussion on: Hooks in React

Collapse
 
cariehl profile image
Cooper Riehl

Good article! I'm new to React, so I would love to see an actual code example of a Hook and how to use it.

Collapse
 
mursalfk profile image
Mursal Furqan Kumbhar

My next article would feature some real-life code examples. Hit the follow button to stay tuned :)

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan • Edited

@cariehl check out this article for React Hooks with actual code examples

Collapse
 
cariehl profile image
Cooper Riehl

Thanks for your article, @myogeshchavan97 ! This was a great explanation.

So from what I understand, React Hooks provide a way to do certain things in functional components, which were previously only possible in class components. Is that about right?

Thread Thread
 
myogeshchavan97 profile image
Yogesh Chavan

Thanks. With the addition of React Hooks, there is now no difference between class components and functional components.

You can do everything in the functional component that the class components offered.

The only difference between them is that there are no available hooks for getSnapshotBeforeUpdate, getDerivedStateFromError and componentDidCatch lifecycle method of class components.

So If you need to use these lifecycle methods, you need to use class components instead of functional components