this.setState is undefined

前端 未结 8 2102
无人及你
无人及你 2020-12-09 01:24

I keep seeing answers that say to use => or .bind(this) but neither of those solutions worked.

import React, { Component } from \'react\';
import { View, Tex         


        
8条回答
  •  鱼传尺愫
    2020-12-09 02:08

    also you can bind this in constructor like this

    class MyClass extends React.Component {
      constructor(props){
        super(props);
        this.handleButtonClick = this.handleButtonClick.bind(this);
     }
      handleButtonClick(){
        console.log("Hello from here");
      }
    
      render() {
        return (
          
        );
      }
    }
    

提交回复
热议问题