State and Props in React
Managing state by using state object in class component.
Props: props helps to transfer the data from parent component to child component.
App.js
import React,{Component} from 'react'
import Display from './Display'
// Class component
export default class App extends Component {
// state management
state = {
name: "Welcome to React JS Tutorial."
}
render(){
return(
<div>
<Display name={this.state.name} />
</div>
)
}
}
Display.js
import React, { Component } from "react";
export default class Display extends Component{
render(){
return(
<div>
<h2>{this.props.name}</h2>
</div>
)
}
}