Skip to content

Commit e9d1845

Browse files
committed
add comment for guards added in useEffects
1 parent 4fbfb36 commit e9d1845

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

libs/isograph-react-disposable-state/src/useCachedResponsivePrecommitValue.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export function useCachedResponsivePrecommitValue<T>(
5151
const lastCommittedParentCache = useRef<ParentCache<T> | null>(null);
5252

5353
useEffect(() => {
54+
// react reruns all `useEffect` in HMR since it doesn't know if the
55+
// code inside of useEffect has changed. Since this is a library
56+
// user can't change this code so we are safe to skip this rerun.
57+
// This also prevents `useEffect` from running twice in Strict Mode.
5458
if (lastCommittedParentCache.current === parentCache) {
5559
return;
5660
}

libs/isograph-react-disposable-state/src/useLazyDisposableState.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export function useLazyDisposableState<T>(
3232

3333
const lastCommittedParentCache = useRef<ParentCache<T> | null>(null);
3434
useEffect(() => {
35+
// react reruns all `useEffect` in HMR since it doesn't know if the
36+
// code inside of useEffect has changed. Since this is a library
37+
// user can't change this code so we are safe to skip this rerun.
38+
// This also prevents `useEffect` from running twice in Strict Mode.
3539
if (lastCommittedParentCache.current === parentCache) {
3640
return;
3741
}

0 commit comments

Comments
 (0)