How to bind onclick handlers to `this` properly on React

后端 未结 2 1565
既然无缘
既然无缘 2020-11-29 13:50

Explanation to why this is not a duplicate: My code is already working, I have included as a comment. The question is why the this context change when I include

2条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 14:48

    Bind it in the constructor

    constructor(props) {
        super(props);
        this.inputDigit = this.inputDigit.bind(this);
    }
    

提交回复
热议问题