Skip to main content
InterviewHubPRO
Section Overview
Q377

Question 377 of 407

Part 9: React Hooks Deep Dive (262 - 316)

93%
React Core & Hooks (407 Qs)•Part 9: React Hooks Deep Dive (262 - 316)

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

junior LevelCode ExampleComponentsHooks

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>
    );
  }
}