-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add React.Suspense component, remove React.useMutationEffect hook #7213
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
Changes from all commits
0a62cb0
bb4646f
6af8901
e762f41
9b45d2b
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 |
|---|---|---|
|
|
@@ -258,6 +258,12 @@ declare module react { | |
| declare export var ConcurrentMode: ({children: ?React$Node}) => React$Node; // 16.7+ | ||
| declare export var StrictMode: ({children: ?React$Node}) => React$Node; | ||
|
|
||
| declare export var Suspense: React$ComponentType<{ | ||
| children?: ?React$Node, | ||
|
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. Is this needed? 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. whoa, that seems like a bug – composite components should only take children if it's explicitly specified (it's only host components like 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. Based on the context 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. FWIW, children is the part of our react model that I'm still not totally familiar with. I'm glad we're having this conversation because it's forcing me to look into it more. @sophiebits: I'll have to do some more investigation. Requiring an explicit children prop would be an extremely disruptive change at this point. @bvaughn: I just took a look at our react docs to see what we say about children types. It looks like we have conflicting advice here and here. I think the 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. @sophiebits: Width subtyping allows extra properties to be passed into an object, so if the Props type is not exact then we allow children even if they are not specified explicitly. On the other hand, if the Props type is exact then we don't allow the extra properties. Mystery solved! 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. for posterity: React's treatment of
|
||
| fallback?: React$Node, | ||
| maxDuration?: number | ||
| }>; // 16.6+ | ||
|
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. Does this imply that this is a class? I guess that isn't technically correct since it's one of those internal special symbols like Fragment but maybe good enough for now. Should it use the same hack as Fragments and pretend to be a functional component? That way maybe refs are invalid maybe? 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.
Then people might think they can call it as a function, which would error? (Doesn't seem like that would obviously be better than this.) 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. ComponentType is the type alias that (currently) represents function components and class components. 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. Is there an alias for something that more accurately represents 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. Not yet, but AbstractComponent will fulfill that role! 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.
If the instance type is void, it's more precise to use the function hack. Since we're already using that hack today, and since it will be fixed as part of my work on AbstractComponent, I think we should use the function representation for now. 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. Ok~ 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. 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. Calling 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.
|
||
|
|
||
| declare export type ElementProps<C> = React$ElementProps<C>; | ||
| declare export type ElementConfig<C> = React$ElementConfig<C>; | ||
| declare export type ElementRef<C> = React$ElementRef<C>; | ||
|
|
@@ -285,7 +291,7 @@ declare module react { | |
| ): React$StatelessFunctionalComponent<P>; | ||
|
|
||
| declare export function lazy<P>( | ||
| component: () => React$ComponentType<P>, | ||
| component: () => Promise<{ default: React$ComponentType<P> }>, | ||
| ): React$ComponentType<P>; | ||
|
|
||
| declare type MaybeCleanUpFn = ?(() => mixed); | ||
|
|
@@ -312,18 +318,13 @@ declare module react { | |
| inputs: ?$ReadOnlyArray<mixed>, | ||
| ): void; | ||
|
|
||
| declare export function useMutationEffect( | ||
| create: () => MaybeCleanUpFn, | ||
| inputs: ?$ReadOnlyArray<mixed>, | ||
| ): void; | ||
|
|
||
| declare export function useLayoutEffect( | ||
| create: () => MaybeCleanUpFn, | ||
| inputs: ?$ReadOnlyArray<mixed>, | ||
| ): void; | ||
|
|
||
| declare export function useCallback<T>( | ||
| callback: () => T | void, | ||
| declare export function useCallback<T: (...args: $ReadOnlyArray<empty>) => mixed>( | ||
| callback: T, | ||
| inputs: ?$ReadOnlyArray<mixed>, | ||
| ): T; | ||
|
|
||
|
|
@@ -358,12 +359,12 @@ declare module react { | |
| +Children: typeof Children, | ||
| +ConcurrentMode: typeof ConcurrentMode, | ||
| +StrictMode: typeof StrictMode, | ||
| +Suspense: typeof Suspense, | ||
| +useContext: typeof useContext, | ||
| +useState: typeof useState, | ||
| +useReducer: typeof useReducer, | ||
| +useRef: typeof useRef, | ||
| +useEffect: typeof useEffect, | ||
| +useMutationEffect: typeof useMutationEffect, | ||
| +useLayoutEffect: typeof useLayoutEffect, | ||
| +useCallback: typeof useCallback, | ||
| +useMemo: typeof useMemo, | ||
|
|
||
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Good catch. I'm ok with adding that fix to this PR or doing it in a separate one.
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.
@bvaughn actually brought up a good point below, it's not quite a ComponentType. It will be an AbstractComponent, though!
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.
Let's leave it for now?
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.
Yeah, sounds good