The sample react app always create function component which is stateless and used a lot now a days.
Let's see how the earlier component types, Class component is created.
So, instead of function, a class is created and render() function is used to return the output.
The class extends from React.Component.
import React from "react"; import "./App.css"; class App extends React.Component { render() { return ( <div className="App"> <h1>Hello from React</h1> </div> ); } } export default App;
You can import the Component sub class also and change the code as below.
import React, { Component } from "react"; import "./App.css"; class App extends Component { render() { return ( <div className="App"> <h1>Hello from React</h1> </div> ); } } export default App;
No comments:
Post a Comment