Rahul
RAHULISM

RAHULISM

What are class components or ES6 classes?

What are class components or ES6 classes?

Rahul
·Mar 28, 2021·

2 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

In the last, we discussed the Functional Components. In this post, we will know about the class component or ES6 Classes.


Intro👋

Class components are ES6 classes. Class components optionally receive props as input ad renders JSX. It can also maintain the private internal state of a particular component.

Example:

class welcome extends Components{
    render()
    {
        return <h1>Hey, {this.props.name}</h1>
    }
}

The component should always start with capital letter and the props should never be modified.


Drawbacks ❎

  • Class components are slight slower than their functional counterparts. The performance difference increases when the number of components in the app increases.

  • Class components involve a lot more coding on the programmer's side making them slightly more inefficient to use.



😫Thanks For Reading | Happy Reacting😴

Did you find this article valuable?

Support Rahul by becoming a sponsor. Any amount is appreciated!

See recent sponsors Learn more about Hashnode Sponsors
 
Share this