menu search
brightness_auto
more_vert
What are components in React? Create one class component “Car” in React and invoke it using index.js
thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike

1 Answer

more_vert
 
verified
Best answer

In React, components are the building blocks that allow you to split the user interface into reusable and independent pieces. Components can be either functional or class-based. They encapsulate the logic and the UI elements related to a specific part of the application. 

 

Example : 

// Car.js

import React, { Component } from 'react';

class Car extends Component {
  render() {
    return (
      <div>
        <h2>Car Component</h2>
        <p>This is a simple car component.</p>
      </div>
    );
  }
}

export default Car;

 

// index.js

import React from 'react';
import ReactDOM from 'react-dom';
import Car from './Car';

// Render the Car component in the root element of the HTML document
ReactDOM.render(<Car />, document.getElementById('root'));


thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike

Related questions

thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
0 answers
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
0 answers
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
0 answers

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

648 users

...