write class in another page and call to index page

 =

import React from 'react';
import ReactDOM from 'react-dom/client';
import Car from './Car'; // Import the Car component

const container = document.getElementById('root');
const root = ReactDOM.createRoot(container);
root.render(<Car />); // Render the Car component


=

// car.js
import React from 'react';

class Car extends React.Component {
  constructor() {
    super();
    this.state = { color: "red" };
  }

  render() {
    return <h2>I am a Car!</h2>;
  }
}

export default Car;

=


No comments:

Post a Comment

Event listening in react

 How we can listen to som eevents some envents fire like click or automatically user enters into input button , that is event on word type i...