Skip to content

Commit f3b4fc7

Browse files
committed
Fix useIsomorphicLayoutEffect in React Native environments
- React Native was not using `useLayoutEffect` which was causing nested component updates to not get properly batched when using the `connect` API [#2150](reduxjs/react-redux#2150).
1 parent c31a0c3 commit f3b4fc7

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/utils/useIsomorphicLayoutEffect.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ export const canUseDOM = !!(
1616
typeof window.document.createElement !== 'undefined'
1717
)
1818

19+
// Under React Native, we know that we always want to use useLayoutEffect
20+
21+
/**
22+
* Checks if the code is running in a React Native environment.
23+
*
24+
* @see {@link https://github.com/facebook/react-native/issues/1331 Reference}
25+
*/
26+
export const isReactNative =
27+
typeof navigator !== 'undefined' && navigator.product === 'ReactNative'
28+
1929
export const useIsomorphicLayoutEffect = canUseDOM
2030
? React.useLayoutEffect
21-
: React.useEffect
31+
: isReactNative
32+
? React.useLayoutEffect
33+
: React.useEffect

0 commit comments

Comments
 (0)