Khaled Touahri
Khaled Touahri

Reputation: 27

When to use class-based component in React

After React Hooks were introduced in React 16.8 with all the new ways to control component's state and lifecycle methods in a functional component such as useState and useEffect, the remaining difference between a functional component and a class-based component isn't obvious anymore, so what's the real difference ?

Upvotes: 2

Views: 141

Answers (1)

flppv
flppv

Reputation: 4289

There are some lifecycle methods, which can't be emulated with React Hooks(e.g. componentDidCatch()).

In this cases you still need class components, but overall, you don't need them, and it's already totally fine, if you have an app without them.

Upvotes: 2

Related Questions