Uncaught TypeError: Cannot read property 'state' of undefined - React

后端 未结 2 2001
忘掉有多难
忘掉有多难 2021-01-22 05:22

I can not figure out if I am missing something small here?

Just trying to get a grasp on how state works with React.

Just creating a small check box that change

2条回答
  •  太阳男子
    2021-01-22 06:00

    Binding your handleCheck function in the constructor:

    constructor(props) {
        super(props);
    
        this.state = {
            checked: true
        };
    
        this.handleCheck = this.handleCheck.bind(this);
    }
    

提交回复
热议问题