Skip to content

Commit

Permalink
Fix useIsomorphicLayoutEffect in React Native environments
Browse files Browse the repository at this point in the history
  - React Native was not using `useLayoutEffect` which was causing nested component updates to not get properly batched when using the `connect` API [#2150](#2150).
  • Loading branch information
aryaemami59 committed Apr 10, 2024
1 parent 05b55c0 commit 5ba0d93
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/utils/useIsomorphicLayoutEffect.ts
Expand Up @@ -16,6 +16,18 @@ export const canUseDOM = !!(
typeof window.document.createElement !== 'undefined'
)

// 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
? React.useLayoutEffect
: React.useEffect
: isReactNative
? React.useLayoutEffect
: React.useEffect

0 comments on commit 5ba0d93

Please sign in to comment.