Skip to content

Commit

Permalink
[PR] [react] New useReducer signature
Browse files Browse the repository at this point in the history
Summary:
React is updating the signature for the `useReducer` hook facebook/react#14723 This PR reflects those changes. We'll also update the official react docs soon.

I'm doing a build and tests right now locally (installing everything from scratch atm), but figured I'd start the PR as well.
Pull Request resolved: #7420

Reviewed By: bvaughn

Differential Revision: D13928051

Pulled By: jbrown215

fbshipit-source-id: 52da18fb52a25ec3b8353696df94cbeb7992e5ef
  • Loading branch information
Sunil Pai authored and facebook-github-bot committed Feb 6, 2019
1 parent 269c339 commit 4f65810
Show file tree
Hide file tree
Showing 8 changed files with 651 additions and 619 deletions.
17 changes: 15 additions & 2 deletions lib/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,24 @@ declare module react {
initialState: (() => S) | S,
): [S, ((S => S) | S) => void];

declare type Dispatch<A> = (A) => void;

declare export function useReducer<S, A>(
reducer: (S, A) => S,
initialState: S,
initialAction: ?A,
): [S, A => void];
): [S, Dispatch<A>];

declare export function useReducer<S, A>(
reducer: (S, A) => S,
initialState: S,
init: void,
): [S, Dispatch<A>];

declare export function useReducer<S, A, I>(
reducer: (S, A) => S,
initialArg: I,
init: (I) => S,
): [S, Dispatch<A>];

declare export function useRef<T>(initialValue: T): {current: T};

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:425:36
425| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:438:36
438| 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:427:36
427| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:440:36
440| 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 @@ -193,8 +193,8 @@ Cannot assign `this.props.x` to `_` because number [1] is incompatible with stri
^^^^^^^^^^^^

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

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

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


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

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

References:
<BUILTINS>/react.js:425:36
425| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:438:36
438| number: React$PropType$Primitive<number>;
^^^^^^ [1]
props.js:16:16
16| var c: string = this.props.z; // error
Expand All @@ -588,14 +588,14 @@ References:
props.js:20:29
20| var element = <TestProps x={false} y={false} z={false} />; // 3 errors
^^^^^ [1]
<BUILTINS>/react.js:427:36
427| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:440:36
440| 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:425:36
425| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:438:36
438| number: React$PropType$Primitive<number>;
^^^^^^ [4]


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

References:
<BUILTINS>/react.js:401:39
<BUILTINS>/react.js:414:39
v
401| type ReactPropsChainableTypeChecker = {
402| isRequired: ReactPropsCheckType;
403| (props: any, propName: string, componentName: string, href?: string): ?Error;
404| };
414| type ReactPropsChainableTypeChecker = {
415| isRequired: ReactPropsCheckType;
416| (props: any, propName: string, componentName: string, href?: string): ?Error;
417| };
^ [1]


Expand Down
Loading

0 comments on commit 4f65810

Please sign in to comment.