score:1

Accepted answer
import React, {Component} from 'react';

class App extends Component{
  state = {
    name:'Aneesh',
    age: '30'
  }

  handleClick= (event)=>{
    //this prints the original state
    console.log(this.state);
    this.setState({
      name:'Rayancha'
    })
    //This prints the original state in the first click and prints the new state after the second click
    console.log(this.state);
  }

  render(){
    console.log(this.state.name)
    return (
      <div>
        <h1>I am app component</h1>
        <p>My name is: {this.state.name} and my Age is {this.state.age}</p>
        <button onClick={this.handleClick}>Click Me</button>
      </div>
    )
  }
}

export default App;

score:1

handleClick= (event)=>{
    this.setState({
      name:'Rayancha'
    }, () => console.log(this.state))
  }

score:2

handleClick= (event)=>{
    //this prints the original state
    console.log(this.state);
    this.setState({
      name:'Rayancha'
    }, () => console.log(this.state))
  }

Related Query

More Query from same tag