React JS - Class Components

What are Class Components?

  • Before React 16.8, Class Components were used.

  • These components are simple classes.

  • All Class components extends parent class Component.

  • render() method is used before return() to display output on browser.

  • They are very rarely used in React Project.
Disadvantages of Class Components

  • Lengthy Code
  • Complex
How to create Class Components?
  • Create a new file inside src/ with any name (Ex : User.js)

  • If you have installed VS Code Extension, then type shortcut rce and press enter.

  • Write your logic.

  • Open index.js and import the component at top and inside <React.StrictMode> call the component :
    <User/>. You can also call the component inside App.js.
Github Link :

INTERVIEW QUESTION
  • What is the shortcut way to write class component structure in VS Code?
    Answer :
    Type rce and press enter.

Comments