Skip to content

Commit

Permalink
Merge pull request #2156 from aryaemami59/fix-RN-useIsomorphicLayoutE…
Browse files Browse the repository at this point in the history
…ffect-issue
  • Loading branch information
markerikson authored Apr 14, 2024
2 parents 05b55c0 + fd2c5c6 commit 0396da3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 0 additions & 5 deletions src/utils/useIsomorphicLayoutEffect.native.ts

This file was deleted.

15 changes: 12 additions & 3 deletions src/utils/useIsomorphicLayoutEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ export const canUseDOM = !!(
typeof window.document.createElement !== 'undefined'
)

export const useIsomorphicLayoutEffect = canUseDOM
? React.useLayoutEffect
: React.useEffect
// Under React Native, we know that we always want to use useLayoutEffect

/**
* Checks if the code is running in a React Native environment.
*
* @see {@link https://github.com/facebook/react-native/issues/1331 Reference}
*/
export const isReactNative =
typeof navigator !== 'undefined' && navigator.product === 'ReactNative'

export const useIsomorphicLayoutEffect =
canUseDOM || isReactNative ? React.useLayoutEffect : React.useEffect

0 comments on commit 0396da3

Please sign in to comment.