DEV Community

Rahul
Rahul

Posted on • Originally published at rahulism.tech

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šŸ˜“

Top comments (0)