score:3

Accepted answer

all you need to do is to change this bit in your code:

this.interval = setinterval(() => this.tick('hi'), 1000);

alternatively, you can also send in this to the callback:

this.interval = setinterval(function(t) {t.tick('hi')}, 1000, this);

see the updated fiddle, here.


setinterval() takes (at least) two parameters, the first one is the callback and needs to be a function. you had provided the code directly; that code must be inside a function.

var intervalid = scope.setinterval(func, delay);

func

a function to be executed every delay milliseconds. the function is not passed any parameters, and no return value is expected.

score:0

change code to:

componentdidmount: function() {
   this.interval = setinterval(()=>this.tick('hi'), 1000);
}

Related Query

More Query from same tag