useIsomorphicLayoutEffect.js 867 B

12345678910
  1. import { useEffect, useLayoutEffect } from 'react'; // React currently throws a warning when using useLayoutEffect on the server.
  2. // To get around it, we can conditionally useEffect on the server (no-op) and
  3. // useLayoutEffect in the browser. We need useLayoutEffect to ensure the store
  4. // subscription callback always has the selector from the latest render commit
  5. // available, otherwise a store update may happen between render and the effect,
  6. // which may cause missed updates; we also must ensure the store subscription
  7. // is created synchronously, otherwise a store update may occur before the
  8. // subscription is created and an inconsistent state may be observed
  9. export var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? useLayoutEffect : useEffect;