ShouldComponentUpdate Life Cycle Method - React Js

 App.js:


import React, { Component, useState } from 'react';

import './App.css'

class App extends Component {
  constructor()
  {
  super()
  console.warn("Constructor")
  // this.state={name:"Krishan"}
  this.state={count:0}
  }
  shouldComponentUpdate()
  {
    console.warn("Should Component Update", this.state.count)
    if(this.state.count<5 && this.state.count<10)
    {
      return true;
    }
 
  }
  render()
  {
    console.warn("Render")
    return (
      <div>
        <h1>Should Component Update {this.state.count}</h1>
        <button onClick={()=>{this.setState({count:this.state.count+1})}}>Update Counter</button>

      </div>
 
    )
  }
 

}

export default App;


Comments

Popular posts from this blog

Send Data Child to Parent Component - React Js

Hide , Show and Toggle in ReactJs

Importance Of Web Content In SEO.