From e7592de518ed226b4eb2fc44036bd8588c3e7c43 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Fri, 24 Mar 2023 16:44:26 +0100 Subject: [PATCH 1/4] useEffectEvent: Highlight wrong types --- packages/react/src/ReactHooks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react/src/ReactHooks.js b/packages/react/src/ReactHooks.js index 7f1bc8d5e133b..4c6a065b7e7dc 100644 --- a/packages/react/src/ReactHooks.js +++ b/packages/react/src/ReactHooks.js @@ -236,6 +236,6 @@ export function useMemoCache(size: number): Array { export function useEffectEvent(callback: T): void { const dispatcher = resolveDispatcher(); - // $FlowFixMe This is unstable, thus optional + // $FlowFixMe[not-a-function] return dispatcher.useEffectEvent(callback); } From d849cbc70c82e82d0ff131a7b19bd6969de0b155 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Fri, 24 Mar 2023 16:44:57 +0100 Subject: [PATCH 2/4] Fix Flow types of useEffectEvent --- packages/react/src/ReactHooks.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/react/src/ReactHooks.js b/packages/react/src/ReactHooks.js index 4c6a065b7e7dc..d7e7aa5458c9f 100644 --- a/packages/react/src/ReactHooks.js +++ b/packages/react/src/ReactHooks.js @@ -234,8 +234,10 @@ export function useMemoCache(size: number): Array { return dispatcher.useMemoCache(size); } -export function useEffectEvent(callback: T): void { +export function useEffectEvent) => Return>( + callback: F, +): F { const dispatcher = resolveDispatcher(); - // $FlowFixMe[not-a-function] + // $FlowFixMe[not-a-function] This is unstable, thus optional return dispatcher.useEffectEvent(callback); } From 048d91b016cfcda766ea91084ee39e73fca3d92c Mon Sep 17 00:00:00 2001 From: eps1lon Date: Fri, 24 Mar 2023 16:50:34 +0100 Subject: [PATCH 3/4] Narrow down FlowFixMe for other hooks as well --- packages/react/src/ReactHooks.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react/src/ReactHooks.js b/packages/react/src/ReactHooks.js index d7e7aa5458c9f..d80a8c3b56a24 100644 --- a/packages/react/src/ReactHooks.js +++ b/packages/react/src/ReactHooks.js @@ -218,19 +218,19 @@ export function useSyncExternalStore( export function useCacheRefresh(): (?() => 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(usable: Usable): 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 { const dispatcher = resolveDispatcher(); - // $FlowFixMe This is unstable, thus optional + // $FlowFixMe[not-a-function] This is unstable, thus optional return dispatcher.useMemoCache(size); } From f932f3450913fa48672ca867af405b7d00fb2001 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Sat, 25 Mar 2023 18:41:58 +0100 Subject: [PATCH 4/4] Simplify useEffectEvent types --- packages/react-reconciler/src/ReactInternalTypes.js | 4 +--- packages/react/src/ReactHooks.js | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/react-reconciler/src/ReactInternalTypes.js b/packages/react-reconciler/src/ReactInternalTypes.js index 7f01daa5240da..a672b9669abcf 100644 --- a/packages/react-reconciler/src/ReactInternalTypes.js +++ b/packages/react-reconciler/src/ReactInternalTypes.js @@ -383,9 +383,7 @@ export type Dispatcher = { create: () => (() => void) | void, deps: Array | void | null, ): void, - useEffectEvent?: ) => Return>( - callback: F, - ) => F, + useEffectEvent?: ) => mixed>(callback: F) => F, useInsertionEffect( create: () => (() => void) | void, deps: Array | void | null, diff --git a/packages/react/src/ReactHooks.js b/packages/react/src/ReactHooks.js index d80a8c3b56a24..6d157cbc60289 100644 --- a/packages/react/src/ReactHooks.js +++ b/packages/react/src/ReactHooks.js @@ -234,7 +234,7 @@ export function useMemoCache(size: number): Array { return dispatcher.useMemoCache(size); } -export function useEffectEvent) => Return>( +export function useEffectEvent) => mixed>( callback: F, ): F { const dispatcher = resolveDispatcher();