Skip to content

Commit deacf1c

Browse files
committed
feat(utils): added useIsomorphicLayoutEffect from react-redux
1 parent cb1d0a1 commit deacf1c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export * from "./getPercentage";
2323
export * from "./nearest";
2424

2525
export * from "./useEnsuredRef";
26+
export * from "./useIsomorphicLayoutEffect";
2627
export { default as useToggle } from "./useToggle";
2728
export { default as useInterval } from "./useInterval";
2829
export { default as useTimeout } from "./useTimeout";
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { useEffect, useLayoutEffect } from "react";
2+
3+
/**
4+
* This is copy/pasted from react-redux which has some more information about
5+
* this and how to fix "invalid" warnings while running tests.
6+
*
7+
* @see https://github.com/reduxjs/react-redux/blob/4c907c0870c6b9a136dd69be294c17d1dc63c8f5/src/utils/useIsomorphicLayoutEffect.js
8+
*/
9+
export const useIsomorphicLayoutEffect =
10+
typeof window !== "undefined" &&
11+
typeof window.document !== "undefined" &&
12+
typeof window.document.createElement !== "undefined"
13+
? useLayoutEffect
14+
: useEffect;

0 commit comments

Comments
 (0)