Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: update useIsomorphicLayoutEffect comment
  • Loading branch information
joshuaellis committed May 5, 2022
commit 8b97d8855ca79299f80eb9364070f5ee58a44abc
16 changes: 9 additions & 7 deletions packages/shared/src/hooks/useIsomorphicLayoutEffect.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useEffect, useLayoutEffect } from 'react'

// For server-side rendering: https://github.com/react-spring/zustand/pull/34
// Deno support: https://github.com/pmndrs/zustand/issues/347
const isSSR =
typeof window === 'undefined' ||
!window.navigator ||
/ServerSideRendering|^Deno\//.test(window.navigator.userAgent)
import { isSSR } from '../helpers'

export const useIsomorphicLayoutEffect = isSSR ? useEffect : useLayoutEffect
/**
* Use this to read layout from the DOM and synchronously
* re-render if the isSSR returns true. Updates scheduled
* inside `useIsomorphicLayoutEffect` will be flushed
* synchronously in the browser, before the browser has
* a chance to paint.
*/
export const useIsomorphicLayoutEffect = isSSR() ? useEffect : useLayoutEffect