class Header extends React.Component{
constructor(){
super() // super is used to call parent constructor
this.State = { // state is special object
title:'Welcome to React',
city: 'Mumbai'
}
}
render() {
return (
<div className='title'>
<h2>{this.State.title}</h2>
<p>{this.State.city}</p>
</div>
);
}
}
export default Header;
Import same Header class in App.js file as follows-
import './App.css';
import Header from './Components/Header/Header.js';
function App() {
return (
<div className="App">
<Header/>
</div>
);
}
export default App;
PostedBy: pankaj_bhakre
No comments:
Post a Comment