Skip to content

Instantly share code, notes, and snippets.

@fivethreeo
Created February 25, 2020 14:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fivethreeo/8527ff4c7b73913b6d6b55204be60c4b to your computer and use it in GitHub Desktop.
Save fivethreeo/8527ff4c7b73913b6d6b55204be60c4b to your computer and use it in GitHub Desktop.
import { useEffect, useLayoutEffect } from 'react';
// eslint-disable-next-line max-len
// See https://github.com/reduxjs/react-redux/blob/316467a/src/hooks/useSelector.js#L6-L15
export const useIsomorphicLayoutEffect =
typeof window !== 'undefined' ? useLayoutEffect : useEffect;
export const useServerNoopLayoutEffect =
typeof window !== 'undefined' ? useLayoutEffect : () => ({});
export const useServerNoopEffect =
typeof window !== 'undefined' ? useEffect : () => ({});
export const useClientNoopEffect =
typeof window !== 'undefined' ? () => ({}) : useEffect;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment