E-mail : support@tech2now.in

How to Create Class in React

Steps to Create Class in React

interface IEmployee {

  name: string

  age: number

  department: string

  designation: string

  joiningDate: Date

}

class Employee implements IEmployee {

  name: string

  age: number

  department: string

  designation: string

  joiningDate: Date

  constructor(name: string, age: number, department: string, designation: string, joiningDate: Date) {

    this.name = name

    this.age = age

    this.department = department

    this.designation = designation

    this.joiningDate = joiningDate

  }

  getDetails(): string {

    return `Name: ${this.name}, Age: ${this.age}, Department: ${this.department}, Designation: ${this.designation}, JoiningDate: ${this.joiningDate}`

  }

}

const employee = new Employee('Anupam', 35, 'IT', 'SE', new Date())

console.log(employee.getDetails())

Response: