Skip to content

Commit c4ed804

Browse files
authored
Extracted useIsomorphicLayoutEffect to a separate file (#3766)
## Description In #3752 I placed useIsomorphicLayoutEffect in utils, but we reached a conclusion that it is better to extract it to its own file. ## Test plan `yarn lint-check`
1 parent 8403694 commit c4ed804

3 files changed

Lines changed: 22 additions & 20 deletions

File tree

packages/react-native-gesture-handler/src/handlers/gestures/GestureDetector/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import { useAnimatedGesture } from './useAnimatedGesture';
1313
import { attachHandlers } from './attachHandlers';
1414
import { needsToReattach } from './needsToReattach';
1515
import { dropHandlers } from './dropHandlers';
16-
import { useIsomorphicLayoutEffect, useWebEventHandlers } from './utils';
16+
import { useWebEventHandlers } from './utils';
1717
import { Wrap, AnimatedWrap } from './Wrap';
1818
import { useDetectorUpdater } from './useDetectorUpdater';
1919
import { useViewRefHandler } from './useViewRefHandler';
2020
import { useMountReactions } from './useMountReactions';
21+
import { useIsomorphicLayoutEffect } from '../../../useIsomorphicLayoutEffect';
2122

2223
function propagateDetectorConfig(
2324
props: GestureDetectorProps,

packages/react-native-gesture-handler/src/handlers/gestures/GestureDetector/utils.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from '../../gestureHandlerCommon';
2020
import { isNewWebImplementationEnabled } from '../../../EnableNewWebImplementation';
2121
import { RNRenderer } from '../../../RNRenderer';
22-
import React, { useCallback, useRef, useState } from 'react';
22+
import { useCallback, useRef, useState } from 'react';
2323
import { Reanimated } from '../reanimatedWrapper';
2424
import { onGestureHandlerEvent } from '../eventReceiver';
2525
import { WebEventHandler } from './types';
@@ -185,21 +185,3 @@ export function useWebEventHandlers() {
185185
: undefined,
186186
});
187187
}
188-
189-
// code below is modified version of the code found in:
190-
// https://github.com/reduxjs/react-redux/blob/7e2fdd4ee2021e4282e12ba9fc722f09124e30cd/src/utils/useIsomorphicLayoutEffect.ts#L36
191-
// React currently throws a warning when using useLayoutEffect on the server.
192-
// To get around it, we can conditionally useEffect on the server (no-op) and
193-
// useLayoutEffect in the browser.
194-
const isDOM = !!(
195-
typeof window !== 'undefined' &&
196-
typeof window.document !== 'undefined' &&
197-
typeof window.document.createElement !== 'undefined'
198-
);
199-
200-
// Under React Native, we know that we always want to use useLayoutEffect
201-
const isReactNative =
202-
typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
203-
204-
export const useIsomorphicLayoutEffect =
205-
isDOM || isReactNative ? React.useLayoutEffect : React.useEffect;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
// code below is modified version of the code found in:
3+
// https://github.com/reduxjs/react-redux/blob/7e2fdd4ee2021e4282e12ba9fc722f09124e30cd/src/utils/useIsomorphicLayoutEffect.ts#L36
4+
// React currently throws a warning when using useLayoutEffect on the server.
5+
// To get around it, we can conditionally useEffect on the server (no-op) and
6+
7+
// useLayoutEffect in the browser.
8+
const isDOM = !!(
9+
typeof window !== 'undefined' &&
10+
typeof window.document !== 'undefined' &&
11+
typeof window.document.createElement !== 'undefined'
12+
);
13+
14+
// Under React Native, we know that we always want to use useLayoutEffect
15+
const isReactNative =
16+
typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
17+
18+
export const useIsomorphicLayoutEffect =
19+
isDOM || isReactNative ? React.useLayoutEffect : React.useEffect;

0 commit comments

Comments
 (0)