State and Props in React

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>
        )
    }
 }

Raviteja Mulukuntla

Hello Viewers! My name is RaviTeja Mulukuntla and I am a senior software engineer working in a reputed IT firm. I like sharing my professional experience and knowledge skills with all users across all the Digital Platforms.

Previous Post Next Post

Contact Form