Skip to content
Permalink
Browse files
feat(utils): added useIsomorphicLayoutEffect from react-redux
  • Loading branch information
mlaursen committed Aug 31, 2020
1 parent cb1d0a1 commit deacf1c01f62adebbfbfbb3f0d5709cdab0cc537
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
@@ -23,6 +23,7 @@ export * from "./getPercentage";
export * from "./nearest";

export * from "./useEnsuredRef";
export * from "./useIsomorphicLayoutEffect";
export { default as useToggle } from "./useToggle";
export { default as useInterval } from "./useInterval";
export { default as useTimeout } from "./useTimeout";
@@ -0,0 +1,14 @@
import { useEffect, useLayoutEffect } from "react";

/**
* This is copy/pasted from react-redux which has some more information about
* this and how to fix "invalid" warnings while running tests.
*
* @see https://github.com/reduxjs/react-redux/blob/4c907c0870c6b9a136dd69be294c17d1dc63c8f5/src/utils/useIsomorphicLayoutEffect.js
*/
export const useIsomorphicLayoutEffect =
typeof window !== "undefined" &&
typeof window.document !== "undefined" &&
typeof window.document.createElement !== "undefined"
? useLayoutEffect
: useEffect;

0 comments on commit deacf1c

Please sign in to comment.