You're trying to call the return value of
refreshApex, which is a Promise. This won't work the way you expect. You need to use a function, so one of any of the following should work.
Function.prototype.bind makes a function with bound parameters. Perfect for this scenario.
setInterval(refreshApex.bind(this, this.wiredData), 5e3);
An arrow function remembers what
this is, and is definitely preferred over the normal
function() whenever you can.
You can also just set another function to do the work.
// ... in your wire handler
Notice how we do not use parentheses to specify parameters, because this would actually call the method, which isn't what we want.
setInterval's first parameter should be some kind of Function. If it is not, you're doing something wrong. If you're ever not sure, a handy trick is to check:
let x = someExpression;
console.log(x instanceof Function); // this will be true if it is.
If you get anything else, you know you've done something wrong. For example:
let x = refreshApex(this.wiredData);
console.log(x instanceof Function); // this is false, it is a Promise.
Finally, a word of caution. Always store the value from
setInterval and call
clearInterval before attempting to set a new one.
this.timerId = setInterval(...);
Also clear the interval in the
If you don't, your method will continue to run every five seconds each time the wire method is called, and you'll end up with a memory leak and degraded performance.