Skip to content

Commit 77cdf0b

Browse files
committed
refactor: store frame scratch in a lazy ref
1 parent 7c36e8f commit 77cdf0b

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

packages/react-native-livechart/src/core/useLiveChartEngine.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,12 @@ export function useLiveChartEngine(
586586
extremaMinTime,
587587
extremaMaxTime,
588588
};
589-
const [frameScratchRef] = useState(() => ({
590-
current: makeEngineFrameScratch(),
591-
}));
589+
const frameScratchRef = useRef<EngineFrameScratch | null>(null);
590+
if (frameScratchRef.current === null) {
591+
// React permits this predictable lazy-ref initialization: https://react.dev/reference/react/useRef#avoiding-recreating-the-ref-contents
592+
// react-doctor-disable-next-line react-doctor/no-ref-current-in-render -- false positive for React's documented lazy-ref exception
593+
frameScratchRef.current = makeEngineFrameScratch();
594+
}
592595

593596
// `autostart=false` registers the frame callback without running it — the live
594597
// loop is fully inert in static mode (the invariant that makes this worth it).

0 commit comments

Comments
 (0)