Skip to content

Commit 269c339

Browse files
Sunil Paifacebook-github-bot
Sunil Pai
authored andcommitted
[PR] [react] useEffect callback returns nothing, or a function that returns nothing
Summary: to match the changes in facebook/react#14119. ran `make` and the tests, seemed ok? Pull Request resolved: #7430 Reviewed By: bvaughn Differential Revision: D13927998 Pulled By: jbrown215 fbshipit-source-id: 1bc0a6673d5f1bc9a58baa7ec30fdd6aace34813
1 parent 475b812 commit 269c339

File tree

4 files changed

+78
-2
lines changed

4 files changed

+78
-2
lines changed

lib/react.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ declare module react {
305305
component: () => Promise<{ default: React$ComponentType<P> }>,
306306
): React$ComponentType<P>;
307307

308-
declare type MaybeCleanUpFn = ?(() => mixed);
308+
declare type MaybeCleanUpFn = void | (() => void);
309309

310310
declare export function useContext<T>(
311311
context: React$Context<T>,

tests/react/react.exp

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3423,6 +3423,42 @@ References:
34233423
^^^^^^^^^^^^^^^^^^^^^ [2]
34243424

34253425

3426+
Error ------------------------------------------------------------------------------------------ useEffect_hook.js:24:19
3427+
3428+
Cannot call `React.useEffect` with async function bound to `create` because a callable signature is missing in
3429+
`Promise` [1] but exists in function type [2] in the return value.
3430+
3431+
useEffect_hook.js:24:19
3432+
24| React.useEffect(async () => {}) // Error: promise is incompatible with function return type
3433+
^^^^^^^^^^^^^^
3434+
3435+
References:
3436+
useEffect_hook.js:24:30
3437+
24| React.useEffect(async () => {}) // Error: promise is incompatible with function return type
3438+
^ [1]
3439+
<BUILTINS>/react.js:308:41
3440+
308| declare type MaybeCleanUpFn = void | (() => void);
3441+
^^^^^^^^^^ [2]
3442+
3443+
3444+
Error ------------------------------------------------------------------------------------------ useEffect_hook.js:25:19
3445+
3446+
Cannot call `React.useEffect` with function bound to `create` because number [1] is incompatible with undefined [2] in
3447+
the return value of the return value.
3448+
3449+
useEffect_hook.js:25:19
3450+
25| React.useEffect(() => () => 123) // Error: cleanup function should not return a value
3451+
^^^^^^^^^^^^^^^
3452+
3453+
References:
3454+
useEffect_hook.js:25:31
3455+
25| React.useEffect(() => () => 123) // Error: cleanup function should not return a value
3456+
^^^ [1]
3457+
<BUILTINS>/react.js:308:47
3458+
308| declare type MaybeCleanUpFn = void | (() => void);
3459+
^^^^ [2]
3460+
3461+
34263462
Error ---------------------------------------------------------------------------------- useImperativeHandle_hook.js:6:3
34273463

34283464
Cannot call `React.useImperativeHandle` because function [1] requires another argument.
@@ -3526,6 +3562,42 @@ References:
35263562
^^^^^^^^^^^^^^^^^^^^^ [2]
35273563

35283564

3565+
Error ------------------------------------------------------------------------------------ useLayoutEffect_hook.js:24:25
3566+
3567+
Cannot call `React.useLayoutEffect` with async function bound to `create` because a callable signature is missing in
3568+
`Promise` [1] but exists in function type [2] in the return value.
3569+
3570+
useLayoutEffect_hook.js:24:25
3571+
24| React.useLayoutEffect(async () => {}) // Error: promise is incompatible with function return type
3572+
^^^^^^^^^^^^^^
3573+
3574+
References:
3575+
useLayoutEffect_hook.js:24:36
3576+
24| React.useLayoutEffect(async () => {}) // Error: promise is incompatible with function return type
3577+
^ [1]
3578+
<BUILTINS>/react.js:308:41
3579+
308| declare type MaybeCleanUpFn = void | (() => void);
3580+
^^^^^^^^^^ [2]
3581+
3582+
3583+
Error ------------------------------------------------------------------------------------ useLayoutEffect_hook.js:25:25
3584+
3585+
Cannot call `React.useLayoutEffect` with function bound to `create` because number [1] is incompatible with
3586+
undefined [2] in the return value of the return value.
3587+
3588+
useLayoutEffect_hook.js:25:25
3589+
25| React.useLayoutEffect(() => () => 123) // Error: cleanup function should not return a value
3590+
^^^^^^^^^^^^^^^
3591+
3592+
References:
3593+
useLayoutEffect_hook.js:25:37
3594+
25| React.useLayoutEffect(() => () => 123) // Error: cleanup function should not return a value
3595+
^^^ [1]
3596+
<BUILTINS>/react.js:308:47
3597+
308| declare type MaybeCleanUpFn = void | (() => void);
3598+
^^^^ [2]
3599+
3600+
35293601
Error ---------------------------------------------------------------------------------------------- useMemo_hook.js:6:3
35303602

35313603
Cannot call `React.useMemo` because function [1] requires another argument.
@@ -4140,7 +4212,7 @@ References:
41404212

41414213

41424214

4143-
Found 242 errors
4215+
Found 246 errors
41444216

41454217
Only showing the most relevant union/intersection branches.
41464218
To see all branches, re-run Flow with --show-all-branches

tests/react/useEffect_hook.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ import React from 'react';
2121
{
2222
React.useEffect(1); // Error: number is incompatible with function type
2323
React.useEffect(() => {}, 1); // Error: number is incompatible with function react-only array
24+
React.useEffect(async () => {}) // Error: promise is incompatible with function return type
25+
React.useEffect(() => () => 123) // Error: cleanup function should not return a value
2426
}

tests/react/useLayoutEffect_hook.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ import React from 'react';
2121
{
2222
React.useLayoutEffect(1); // Error: number is incompatible with function type
2323
React.useLayoutEffect(() => {}, 1); // Error: number is incompatible with function react-only array
24+
React.useLayoutEffect(async () => {}) // Error: promise is incompatible with function return type
25+
React.useLayoutEffect(() => () => 123) // Error: cleanup function should not return a value
2426
}

0 commit comments

Comments
 (0)