Skip to content

Commit

Permalink
[PR] Add React.Suspense component, remove React.useMutationEffect hook
Browse files Browse the repository at this point in the history
Summary:
Resolves #7219

- [x] 2fdcda5: Removed `React.useMutationEffect` hook (facebook/react/pull/14336) and updated tests. This hook was only ever exposed in an alpha release of 16.7 and so it should be safe to remove in a non-backwards-compatible way.
- [x] dabf49e: Add `React.Suspense` component and tests. (No final public documentation exists for `Suspense` yet– although we're working on it. For the time being, [tests like this](https://github.com/facebook/react/blob/master/packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js) can serve as a reference.)
- [x] 8df05bd: Fixed invalid `useCallback` definition and tests.
- [x] 063b022: Fixed invalid `React.lazy` signature to reflect that a `Promise` with a "default" property should be returned (rather than a React component).
Pull Request resolved: #7213

Reviewed By: jbrown215

Differential Revision: D13222880

Pulled By: bvaughn

fbshipit-source-id: 9e1b48ace984051928c4ab92fa61182ad70f7119
  • Loading branch information
Brian Vaughn authored and glevi committed Dec 4, 2018
1 parent 03f771a commit 5e6beef
Show file tree
Hide file tree
Showing 12 changed files with 979 additions and 374 deletions.
19 changes: 10 additions & 9 deletions lib/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
fallback?: React$Node,
maxDuration?: number
}>; // 16.6+

declare export type ElementProps<C> = React$ElementProps<C>;
declare export type ElementConfig<C> = React$ElementConfig<C>;
declare export type ElementRef<C> = React$ElementRef<C>;
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions tests/getters_and_setters/getters_and_setters.exp
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ References:
react.js:17:13
17| (<Example a="bad" />); // error: number ~> string
^^^^^ [1]
<BUILTINS>/react.js:410:36
410| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:411:36
411| number: React$PropType$Primitive<number>;
^^^^^^ [2]


Expand All @@ -482,8 +482,8 @@ References:
react.js:18:20
18| (<Example a={0} c={0} />); // error: number ~> string
^ [1]
<BUILTINS>/react.js:412:36
412| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:413:36
413| string: React$PropType$Primitive<string>;
^^^^^^ [2]


Expand Down
46 changes: 23 additions & 23 deletions tests/new_react/new_react.exp
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ Cannot assign `this.props.x` to `_` because number [1] is incompatible with stri
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:410:36
410| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:411:36
411| number: React$PropType$Primitive<number>;
^^^^^^ [1]
classes.js:57:12
57| var _: string = this.props.x;
Expand Down Expand Up @@ -388,8 +388,8 @@ Cannot assign `this.props.z` to `qux` because:
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:410:36
410| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:411:36
411| number: React$PropType$Primitive<number>;
^^^^^^ [1]
new_react.js:19:18
19| var qux: string = this.props.z;
Expand All @@ -405,8 +405,8 @@ Cannot assign `this.props.x` to `w` because string [1] is incompatible with numb
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:412:36
412| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:413:36
413| string: React$PropType$Primitive<string>;
^^^^^^ [1]
new_react.js:20:15
20| var w:number = this.props.x;
Expand Down Expand Up @@ -439,8 +439,8 @@ References:
new_react.js:29:23
29| var element = <C x = {0}/>;
^ [1]
<BUILTINS>/react.js:412:36
412| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:413:36
413| string: React$PropType$Primitive<string>;
^^^^^^ [2]


Expand Down Expand Up @@ -545,8 +545,8 @@ Cannot assign `this.props.x` to `a` because:
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:412:36
412| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:413:36
413| string: React$PropType$Primitive<string>;
^^^^^^ [1]
props.js:14:16
14| var a: number = this.props.x; // error
Expand Down Expand Up @@ -582,8 +582,8 @@ Cannot assign `this.props.z` to `c` because:
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:410:36
410| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:411:36
411| number: React$PropType$Primitive<number>;
^^^^^^ [1]
props.js:16:16
16| var c: string = this.props.z; // error
Expand All @@ -604,14 +604,14 @@ References:
props.js:20:29
20| var element = <TestProps x={false} y={false} z={false} />; // 3 errors
^^^^^ [1]
<BUILTINS>/react.js:412:36
412| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:413:36
413| string: React$PropType$Primitive<string>;
^^^^^^ [2]
props.js:20:49
20| var element = <TestProps x={false} y={false} z={false} />; // 3 errors
^^^^^ [3]
<BUILTINS>/react.js:410:36
410| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:411:36
411| number: React$PropType$Primitive<number>;
^^^^^^ [4]


Expand Down Expand Up @@ -668,8 +668,8 @@ References:
props2.js:9:41
9| getInitialState: function(): { bar: number } {
^^^^^^ [1]
<BUILTINS>/react.js:412:36
412| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:413:36
413| string: React$PropType$Primitive<string>;
^^^^^^ [2]
props2.js:15:42
15| return <C {...this.state} foo = {0} />;
Expand Down Expand Up @@ -700,12 +700,12 @@ Cannot get `React.PropTypes.string.inRequired` because property `inRequired` is
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/react.js:386:39
<BUILTINS>/react.js:387:39
v
386| type ReactPropsChainableTypeChecker = {
387| isRequired: ReactPropsCheckType;
388| (props: any, propName: string, componentName: string, href?: string): ?Error;
389| };
387| type ReactPropsChainableTypeChecker = {
388| isRequired: ReactPropsCheckType;
389| (props: any, propName: string, componentName: string, href?: string): ?Error;
390| };
^ [1]


Expand Down
Loading

0 comments on commit 5e6beef

Please sign in to comment.