Skip to content

Commit 9809bf5

Browse files
committed
Revert "feat: use useInsertionEffect instead of useLayoutEffect"
This reverts commit 4acdb34.
1 parent 9c75d2f commit 9809bf5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import * as React from 'react';
22

3+
/**
4+
* Use `useEffect` during SSR and `useLayoutEffect` in the Browser & React Native to avoid warnings.
5+
*/
6+
const useClientLayoutEffect =
7+
typeof document !== 'undefined' ||
8+
(typeof navigator !== 'undefined' && navigator.product === 'ReactNative')
9+
? React.useLayoutEffect
10+
: React.useEffect;
11+
312
/**
413
* React hook which returns the latest callback without changing the reference.
514
*/
@@ -14,7 +23,7 @@ function useLatestCallback<T extends Function>(callback: T): T {
1423
return ref.current.apply(this, args);
1524
} as unknown as T).current;
1625

17-
React.useInsertionEffect(() => {
26+
useClientLayoutEffect(() => {
1827
ref.current = callback;
1928
});
2029

0 commit comments

Comments
 (0)