-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Fix Flow types of useEffectEvent #26468
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -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, Return, F: (...Array<Args>) => Return>( | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a little bit shorter, we don't have to define the return type in the type constraint for F:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Applied in facebook/react@ |
||||||||
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); | ||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kassens Do we actually need the
Args
andReturn
type parameter here? In TS we can just douseEffectEvent<T extends Function>
. Does something similar exist in Flow?