DEV Community

loading...

Discussion on: Do you still use React classes?

Collapse
napoleon039 profile image
Nihar Raote

Ever since Hooks were introduced, I have used them instead of classes. For me, I like the way useState initializes and updates the state. This is a personal preference, but I like using functional components more than classes. This does not mean I have a problem with class-based components or hate them.

I do use classes occasionally. Especially when something needs to be done after a component has been unmounted or when the component is updated. I still can't get around to using useEffect well. I find componentWillUnmount and componentDidUpdate easier to use.

As for which one is better, I think both get the job done when it truly matters. It all depends on whether a library needs classes or the developer prefers one over the other.