Skip to content

Commit

Permalink
fix next.js warning for useLayoutEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
goldsrc committed Jan 17, 2024
1 parent 365ee2b commit f423da2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/useMergeRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { assignRef } from './assignRef';
import { ReactRef } from './types';
import { useCallbackRef } from './useRef';

const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;

const currentValues = new WeakMap<any, ReactRef<any>[]>();

/**
Expand All @@ -26,7 +28,7 @@ export function useMergeRefs<T>(refs: ReactRef<T>[], defaultValue?: T): React.Mu
);

// handle refs changes - added or removed
React.useLayoutEffect(() => {
useIsomorphicLayoutEffect(() => {
const oldValue = currentValues.get(callbackRef);

if (oldValue) {
Expand Down

0 comments on commit f423da2

Please sign in to comment.