mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Align ref helper flow types (#57850)
Summary: Pull Request resolved: https://github.com/react/react-native/pull/57850 React ref callbacks may return only `void` or a cleanup function. Align `TRefCallbackFor` and the related shared callback-ref helpers directly with the core Flow React ref types, then update consumers whose callbacks returned incompatible values. This keeps the contracts canonical and avoids introducing a parallel restricted variant. Changelog: [Internal] - Align ref helper types with the React callback contract. Reviewed By: SamChou19815 Differential Revision: D115064072 fbshipit-source-id: b308ac2b9a453b494c64bdf3d37873b69040ce4c
This commit is contained in:
1 parent
37dd4044fd
commit
88820254e5
2 files changed
+3
-6
No files matched your search
@@ -10,8 +10,6 @@
|
||||
|
||||
import {useCallback, useRef} from 'react';
|
||||
|
||||
type CallbackRef<T> = T => unknown;
|
||||
|
||||
/**
|
||||
* Constructs a callback ref that provides similar semantics as `useEffect`. The
|
||||
* supplied `effect` callback will be called with non-null component instances.
|
||||
@@ -28,7 +26,7 @@ type CallbackRef<T> = T => unknown;
|
||||
*/
|
||||
export default function useRefEffect<TInstance>(
|
||||
effect: TInstance => (() => void) | void,
|
||||
): CallbackRef<TInstance | null> {
|
||||
): React.RefCallback<TInstance> {
|
||||
const cleanupRef = useRef<(() => void) | void>(undefined);
|
||||
return useCallback(
|
||||
(instance: null | TInstance) => {
|
||||
|
||||
@@ -35,11 +35,10 @@ type ReducedProps<TProps> = {
|
||||
collapsable: boolean,
|
||||
...
|
||||
};
|
||||
type CallbackRef<T> = T => unknown;
|
||||
|
||||
export type AnimatedPropsHook = <TProps extends {...}, TInstance>(
|
||||
props: TProps,
|
||||
) => [ReducedProps<TProps>, CallbackRef<TInstance | null>];
|
||||
) => [ReducedProps<TProps>, React.RefCallback<TInstance>];
|
||||
|
||||
type UpdateCallback = () => void;
|
||||
|
||||
@@ -55,7 +54,7 @@ export default function createAnimatedPropsHook(
|
||||
|
||||
return function useAnimatedProps<TProps extends {...}, TInstance>(
|
||||
props: TProps,
|
||||
): [ReducedProps<TProps>, CallbackRef<TInstance | null>] {
|
||||
): [ReducedProps<TProps>, React.RefCallback<TInstance>] {
|
||||
const [, scheduleUpdate] = useReducer<number, void>(count => count + 1, 0);
|
||||
const onUpdateRef = useRef<UpdateCallback | null>(null);
|
||||
const timerRef = useRef<TimeoutID | null>(null);
|
||||
|
||||
Reference in new issue
Block a user