ScanSkill

Class Component

A class Component is simply a class that is made up of multiple functions. The class component includes extends React.Component statement, which creates an inheritance to React.Component, and gives access to react component's functions. The class component uses the render() method to render what needs to be rendered. Class component is also known as a stateful component as it has its own state.

Syntax

import React, { Component } from 'react';

class ComponentName extends Component {
  render() {
    return (
      //JSX goes here
    );
  }
}

export default ComponentName ;

Example

import React, { Component } from 'react';

class MyComponent extends Component {
  render() {
    return (
      <div>Hello World!</div>
    );
  }
}

export default MyComponent;
Class Component