Skip to content

Commit

Permalink
drop node detection in useIsomorphicLayoutEffect
Browse files Browse the repository at this point in the history
drop node detection as breaks unit tests and adds unecessary specificity
  • Loading branch information
patricksmms committed Jan 8, 2020
1 parent 21c8901 commit b66597e
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/utils/useIsomorphicLayoutEffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ import { useEffect, useLayoutEffect } from 'react'

const isBrowser =
typeof window !== 'undefined' &&
typeof window.innerWidth !== 'undefined' &&
typeof window.document !== 'undefined' &&
typeof window.document.createElement !== 'undefined'

const isNode =
typeof process !== 'undefined' &&
process.versions != null &&
process.versions.node != null

// React currently throws a warning when using useLayoutEffect on the server.
// To get around it, we can conditionally useEffect on the server (no-op) and
// useLayoutEffect in the browser. We need useLayoutEffect to ensure the store
Expand All @@ -19,5 +15,4 @@ const isNode =
// is created synchronously, otherwise a store update may occur before the
// subscription is created and an inconsistent state may be observed

export const useIsomorphicLayoutEffect =
isBrowser && !isNode ? useLayoutEffect : useEffect
export const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : useEffect

0 comments on commit b66597e

Please sign in to comment.