Skip to content

Commit

Permalink
add comment for guards added in useEffects
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykWalach committed Jan 3, 2025
1 parent ef89d4d commit c8d6a76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export function useCachedResponsivePrecommitValue<T>(
const lastCommittedParentCache = useRef<ParentCache<T> | null>(null);

useEffect(() => {
// react reruns all `useEffect` in HMR since it doesn't know if the
// code inside of useEffect has changed. Since this is a library
// user can't change this code so we are safe to skip this rerun.
// This also prevents `useEffect` from running twice in Strict Mode.
if (lastCommittedParentCache.current === parentCache) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export function useLazyDisposableState<T>(

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

0 comments on commit c8d6a76

Please sign in to comment.