Tal
Tal

Reputation: 655

React typescript FC vs Component

I am using react with typescript. What is the difference between FC vs Component?

Which is best practice?

Use cases for each?

Does Component is deprecated since react latest version with hooks is not using classes?

Upvotes: 1

Views: 1449

Answers (1)

ysfaran
ysfaran

Reputation: 6952

"old" react (< v16.8) vs "new" react (>= v.16.8)

(following is just my MHO)

"Old" react is not deprecated yet and react team is also not planning to remove class components in near future. But in general using react hooks is highly recommended by react developers. Also it is a more functional approach, which might be good or bad for you depending on your experience. (btw i prefer functional programming)

State

  • old: only class components can maintain state
  • new: functional components can also maintain state (useState hook). Also it's much easier to share stateful logic accross very different components

Lifecycle methods

  • old: only class components can declare lifecycle methods
  • new: functional components can also react on lifecycle events (useEffect hook)

Context API

  • old: IMHO a bit clunky and confusing
  • new: IMHO much cleaner and easier to use (useContext hook)

This are just the main differences for more details see here.

Upvotes: 2

Related Questions