0

I need the this.setState inside my function but I am unable to understand the process. please see the image below

enter image description here

I need the this keyword to solve my problem

NIKHIL CHANDRA ROY
  • 807
  • 11
  • 16
  • change `timeUpdating` to an arrow function so that `this` refers to your component, or, use `timeUpdating.bind(this)` to predefine what `this` will refer to in your `timeUpdating` method – Nick Parsons Feb 01 '20 at 07:28
  • I need bind I tried , ``` function timeUpdating(){ pressWord--; if(pressWord===0) clearInterval(setTime); timeUpdating.bind(this).setState({runTime: pressWord}) } ``` but not working man – NIKHIL CHANDRA ROY Feb 01 '20 at 07:35
  • 1
    If you read the duplicate above it will clarify my comment. But you need to use `.bind()` in the setInterval: `let setTime = setInterval(timeUpdating.bind(this), 1000)`, this will make it so the `this` inside your function refers to your component `this` rather than the global object (ie: window) – Nick Parsons Feb 01 '20 at 07:37

0 Answers0