Error: this.setstate() is not a function in ReactJS

We can get this error inside a function call. Remember to bind that function.

constructor(props){
    super(props);
    this.clear=this.clear.bind(this); // remember to bind your function.
    this.state{
      name=''
    };
  }

  public clear():void{
    this.setState({name:'Akanksha'}); // error here
  }
Power Platform Academy

Start or Upgrade your Career with Power Platform

Learn with Akanksha

Python | Azure | AI/ML | OpenAI | MLOps

Design a site like this with WordPress.com
Get started