Skip to content

Commit

Permalink
Feat(web-react): Introduce useIsomorphicLayoutEffect hook
Browse files Browse the repository at this point in the history
  • Loading branch information
literat committed Nov 8, 2023
1 parent 8e8ea36 commit a7f3c1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/web-react/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export * from './useClassNamePrefix';
export * from './styleProps';
export * from './useCancelEvent';
export * from './useClassNamePrefix';
export * from './useClickOutside';
export * from './useDeprecationMessage';
export * from './useDragAndDrop';
export * from './useIcon';
export * from './useIsomorphicLayoutEffect';
export * from './useLastActiveFocus';
export * from './useToggle';
export * from './styleProps';
9 changes: 9 additions & 0 deletions packages/web-react/src/hooks/useIsomorphicLayoutEffect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* This file fixes the problem of using useLayoutEffect hook on the server side.
* @see https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
* @see https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a
*/
/* eslint-disable no-restricted-imports */
import { useEffect, useLayoutEffect } from 'react';

export const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;

0 comments on commit a7f3c1d

Please sign in to comment.