7 January 2020

Class Component in React JS

  • Create Components folder under src folder
  • Add ClassComponents.js file and add below Code
import React,{Component} from 'react';

class ClassComponents extends Component{
render(){
return(
<div>Class Components</div>
);
}
}
export default ClassComponents;
  • Open index.js file and update code as below
import React from "react";
import ReactDOM from "react-dom";

import "./styles.css";
import ClassComponents from "./Components/ClassComponents";

function App() {
return (
<div className="App">
<ClassComponents />
</div>
);
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Output:

No comments:

Post a Comment