InterviewHubPRO
Section Overview
Q414

Question 414 of 445

Part 11: Legacy Architecture, Migration Patterns & Historical Internals (354 - 445)

93%
React & Modern Frontend (445 Qs)•Part 11: Legacy Architecture, Migration Patterns & Historical Internals (354 - 445)

What is the required method to be defined for a class component?

The render() method is the only required method in a class component. i.e, All methods other than render method are optional for a class component.

Code Example

tsx
import React, { Component } from 'react';

// render() is the only required method when extending React.Component
export class MinimalClassComponent extends Component<{ title: string }> {
  render() {
    return (
      <header className="p-4 bg-slate-100 rounded">
        <h1 className="text-xl font-bold">{this.props.title}</h1>
      </header>
    );
  }
}