Skip to content

Commit c202c8a

Browse files
akwasniewskij-piasecki
authored andcommitted
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 1cf805a commit c202c8a

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
@@ -9,11 +9,12 @@ import { useAnimatedGesture } from './useAnimatedGesture';
99
import { attachHandlers } from './attachHandlers';
1010
import { needsToReattach } from './needsToReattach';
1111
import { dropHandlers } from './dropHandlers';
12-
import { useIsomorphicLayoutEffect, useWebEventHandlers } from './utils';
12+
import { useWebEventHandlers } from './utils';
1313
import { Wrap, AnimatedWrap } from './Wrap';
1414
import { useDetectorUpdater } from './useDetectorUpdater';
1515
import { useViewRefHandler } from './useViewRefHandler';
1616
import { useMountReactions } from './useMountReactions';
17+
import { useIsomorphicLayoutEffect } from '../../../useIsomorphicLayoutEffect';
1718

1819
function propagateDetectorConfig(
1920
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
@@ -15,7 +15,7 @@ import { hoverGestureHandlerProps } from '../hoverGesture';
1515
import { nativeViewGestureHandlerProps } from '../../NativeViewGestureHandler';
1616
import { baseGestureHandlerWithDetectorProps } from '../../gestureHandlerCommon';
1717
import { RNRenderer } from '../../../RNRenderer';
18-
import React, { useCallback, useRef, useState } from 'react';
18+
import { useCallback, useRef, useState } from 'react';
1919
import { Reanimated } from '../reanimatedWrapper';
2020
import { onGestureHandlerEvent } from '../eventReceiver';
2121
import {
@@ -186,21 +186,3 @@ export function useWebEventHandlers() {
186186
},
187187
});
188188
}
189-
190-
// code below is modified version of the code found in:
191-
// https://github.com/reduxjs/react-redux/blob/7e2fdd4ee2021e4282e12ba9fc722f09124e30cd/src/utils/useIsomorphicLayoutEffect.ts#L36
192-
// React currently throws a warning when using useLayoutEffect on the server.
193-
// To get around it, we can conditionally useEffect on the server (no-op) and
194-
// useLayoutEffect in the browser.
195-
const isDOM = !!(
196-
typeof window !== 'undefined' &&
197-
typeof window.document !== 'undefined' &&
198-
typeof window.document.createElement !== 'undefined'
199-
);
200-
201-
// Under React Native, we know that we always want to use useLayoutEffect
202-
const isReactNative =
203-
typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
204-
205-
export const useIsomorphicLayoutEffect =
206-
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)