Skip to content
doubtly

1 answer

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


Doubtly · 24 Nov 2023 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.