During initialization of the component, a value is fetched from the ngrx store and used as a configuration.
this.storeService.selectMConfig().subscribe(res => {
if (!res) return;
const refreshValue = Number(res.items[0].value) * 1000;
this.intervalValue = refreshValue ?? 10000;
});
The goal is to pass this value into the setInterval function for customization.
In the initial version, data is fetched every 10 seconds, but the intention is to make it configurable.
In the second version, this.intervalValue
is used with a value of 10000.
However, an infinite loop is being triggered, and it's unclear why or how to resolve it.
Why is it not functioning properly with a variable?
//v1
setInterval(() => {
this.storeService.fetchData(this.payload);
}, 10000);
//v2
setInterval(() => {
this.storeService.fetchPnrDashboardDetailsForMap(this.mapDetailsPayload);
console.log('settimeout', this.mapRefreshConfig); // this.mapRefreshConfig = 10000
}, this.mapRefreshConfig);