Skip to content

Commit 2456a97

Browse files
Copilotgedinakova
andauthored
fix: replace incorrect setState null guard with mountedRef pattern in high-frequency chart
Agent-Logs-Url: https://github.com/IgniteUI/igniteui-react-examples/sessions/a777979d-98e9-46cf-adc5-3df39b356ec9 Co-authored-by: gedinakova <16817847+gedinakova@users.noreply.github.com>
1 parent a7a4520 commit 2456a97

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

samples/charts/category-chart/high-frequency/src/CategoryChartHighFrequencyFunctional.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ export default function CategoryChartHighFrequency() {
2727
refreshInfo: '5ms',
2828
});
2929

30+
const mountedRef = useRef(true);
31+
3032
const setupInterval = useCallback(() => {
3133
if (intervalRef.current >= 0) {
3234
window.clearInterval(intervalRef.current);
3335
intervalRef.current = -1;
3436
}
3537
intervalRef.current = window.setInterval(() => {
36-
// Only tick when feed is "Stop" (i.e. actively streaming)
37-
if (setState === null) return; // guard against unmounted ref
38+
if (!mountedRef.current) return;
3839
setState(prev => {
3940
if (prev.dataFeedAction !== 'Stop') return prev;
4041

@@ -61,6 +62,7 @@ export default function CategoryChartHighFrequency() {
6162
setupInterval();
6263
}
6364
return () => {
65+
mountedRef.current = false;
6466
if (intervalRef.current >= 0) {
6567
window.clearInterval(intervalRef.current);
6668
intervalRef.current = -1;

0 commit comments

Comments
 (0)