Why does React warn me against binding a component method to the object?

后端 未结 2 1757
暖寄归人
暖寄归人 2020-12-18 21:52

I have this here component. I want to pass down a call handler to each listElement I create. If I do it like below, with bind(this), it works properly. The prob

2条回答
  •  醉梦人生
    2020-12-18 22:36

    The error is coming from somewhere else in the code. You get the error when you do this.someFunction.bind(something) and something isn't null.

    this.someFunction.bind({}, foo);    // warning
    this.someFunction.bind(this, foo);  // warning, you're doing this
    this.someFunction.bind(null, foo);  // okay!
    

    Do a search for .bind(this in your code to find the offending line.

提交回复
热议问题