Skip to content

Commit fa5d1e7

Browse files
committed
fix: react 19 typescript compatibility
- useStableCallback: add initial value to useRef (React 19 requirement) - types.d.ts: change ScrollEventsHandlersHookType ref parameter from React.RefObject to AnimatedRef (fixes type mismatch with useAnimatedRef) - BottomSheetModal: cast through unknown for generic forwardRef + memo pattern (standard workaround for React 19 stricter types) Closes #2363
1 parent b378f29 commit fa5d1e7

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/components/bottomSheetModal/BottomSheetModal.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,9 @@ function BottomSheetModalComponent<T = any>(
465465
) : null;
466466
}
467467

468-
const BottomSheetModal = memo(forwardRef(BottomSheetModalComponent)) as <
468+
const BottomSheetModal = memo(
469+
forwardRef(BottomSheetModalComponent)
470+
) as unknown as <
469471
// biome-ignore lint/suspicious/noExplicitAny: Using 'any' allows users to define their own strict types for 'data' property.
470472
T = any,
471473
>(
@@ -474,7 +476,7 @@ const BottomSheetModal = memo(forwardRef(BottomSheetModalComponent)) as <
474476
}
475477
) => ReturnType<typeof BottomSheetModalComponent>;
476478
(
477-
BottomSheetModal as React.MemoExoticComponent<
479+
BottomSheetModal as unknown as React.MemoExoticComponent<
478480
typeof BottomSheetModalComponent
479481
>
480482
).displayName = 'BottomSheetModal';

src/hooks/useStableCallback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Callback<T extends unknown[], R> = (...args: T) => R;
88
export function useStableCallback<T extends unknown[], R>(
99
callback: Callback<T, R>
1010
) {
11-
const callbackRef = useRef<Callback<T, R>>();
11+
const callbackRef = useRef<Callback<T, R> | undefined>(undefined);
1212

1313
useLayoutEffect(() => {
1414
callbackRef.current = callback;

src/types.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type {
1818
State,
1919
} from 'react-native-gesture-handler';
2020
import type {
21+
AnimatedRef,
2122
EasingFunction,
2223
EasingFunctionFactory,
2324
ReduceMotion,
@@ -30,7 +31,6 @@ import type {
3031
ANIMATION_STATUS,
3132
GESTURE_SOURCE,
3233
KEYBOARD_STATUS,
33-
SCROLLABLE_STATUS,
3434
SCROLLABLE_TYPE,
3535
} from './constants';
3636

@@ -226,7 +226,7 @@ type ScrollEventHandlerCallbackType<C = never> = (
226226
) => void;
227227

228228
export type ScrollEventsHandlersHookType = (
229-
ref: React.RefObject<Scrollable>,
229+
ref: AnimatedRef<Scrollable>,
230230
contentOffsetY: SharedValue<number>
231231
) => {
232232
handleOnScroll?: ScrollEventHandlerCallbackType;

0 commit comments

Comments
 (0)