mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fix Flow types of useEffectEvent (#26468)
## Summary Just copied the types over from the internal types. Type error was hidden by overly broad FlowFixMe. With `$FlowFixMe[not-a-function]` we would've seen the actual issue: ``` Cannot return `dispatcher.useEffectEvent(...)` because `T` [1] is incompatible with undefined [2].Flow(incompatible-return) ``` ## How did you test this change? - [x] yarn flow dom-node - [x] CI
This commit is contained in:
committed by
GitHub
parent
73b6435ca4
commit
d12bdcda69
+1
-3
@@ -383,9 +383,7 @@ export type Dispatcher = {
|
||||
create: () => (() => void) | void,
|
||||
deps: Array<mixed> | void | null,
|
||||
): void,
|
||||
useEffectEvent?: <Args, Return, F: (...Array<Args>) => Return>(
|
||||
callback: F,
|
||||
) => F,
|
||||
useEffectEvent?: <Args, F: (...Array<Args>) => mixed>(callback: F) => F,
|
||||
useInsertionEffect(
|
||||
create: () => (() => void) | void,
|
||||
deps: Array<mixed> | void | null,
|
||||
|
||||
@@ -218,24 +218,26 @@ export function useSyncExternalStore<T>(
|
||||
|
||||
export function useCacheRefresh(): <T>(?() => T, ?T) => void {
|
||||
const dispatcher = resolveDispatcher();
|
||||
// $FlowFixMe This is unstable, thus optional
|
||||
// $FlowFixMe[not-a-function] This is unstable, thus optional
|
||||
return dispatcher.useCacheRefresh();
|
||||
}
|
||||
|
||||
export function use<T>(usable: Usable<T>): T {
|
||||
const dispatcher = resolveDispatcher();
|
||||
// $FlowFixMe This is unstable, thus optional
|
||||
// $FlowFixMe[not-a-function] This is unstable, thus optional
|
||||
return dispatcher.use(usable);
|
||||
}
|
||||
|
||||
export function useMemoCache(size: number): Array<any> {
|
||||
const dispatcher = resolveDispatcher();
|
||||
// $FlowFixMe This is unstable, thus optional
|
||||
// $FlowFixMe[not-a-function] This is unstable, thus optional
|
||||
return dispatcher.useMemoCache(size);
|
||||
}
|
||||
|
||||
export function useEffectEvent<T>(callback: T): void {
|
||||
export function useEffectEvent<Args, F: (...Array<Args>) => mixed>(
|
||||
callback: F,
|
||||
): F {
|
||||
const dispatcher = resolveDispatcher();
|
||||
// $FlowFixMe This is unstable, thus optional
|
||||
// $FlowFixMe[not-a-function] This is unstable, thus optional
|
||||
return dispatcher.useEffectEvent(callback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user