1

Recently, I started learning React and I have built both functional and class components. I hear from the grapevine that functional components are preferred since they are simpler and have performance advantages, but class components are more powerful.

Can somebody explain to me the advantage of using a class component in lieu of a functional component in React?

2 Answers 2

1

React has evolved quite a bit and today it is more of a preference what to use. But should be noted that the React team is supporting more React hooks for functional components that replace or even improve upon class components. To follow up, React has performance optimizations in functional components by avoiding unnecessary checks and memory allocations. As of today, there is no difference in render time between rendering class and functional components.

Sign up to request clarification or add additional context in comments.

Comments

0

Functional components should be used all the time. Here are a couple reasons why:

  1. Functional Component source code is easier to read and maintain.
  2. Functional Components have much wider support than class-based components and have a much larger user base than class-based components.

This Reddit thread explains it very well: https://www.reddit.com/r/reactjs/comments/zqo6th/functional_vs_class_components/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.