Skip to content

Fix Flow types of useEffectEvent #26468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/react-reconciler/src/ReactInternalTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions packages/react/src/ReactHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}