DEV Community

Rahul
Rahul

Posted on • Originally published at rahulism.tech

1

What are class components or ES6 classes?

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>
    }
}
Enter fullscreen mode Exit fullscreen mode

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.


Related Posts


😫Thanks For Reading | Happy Reacting😴

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay