Skip to content

Commit c9074ed

Browse files
committedNov 6, 2018
Restrict effect return type to a function or nothing
We already warn in dev if the wrong type is returned. This updates the Flow type.
1 parent affb2b5 commit c9074ed

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed
 

‎packages/react-debug-tools/src/ReactDebugHooks.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function useRef<T>(initialValue: T): {current: T} {
141141
}
142142

143143
function useMutationEffect(
144-
create: () => mixed,
144+
create: () => (() => mixed) | null | void,
145145
inputs: Array<mixed> | void | null,
146146
): void {
147147
nextHook();
@@ -153,7 +153,7 @@ function useMutationEffect(
153153
}
154154

155155
function useLayoutEffect(
156-
create: () => mixed,
156+
create: () => (() => mixed) | null | void,
157157
inputs: Array<mixed> | void | null,
158158
): void {
159159
nextHook();
@@ -165,7 +165,7 @@ function useLayoutEffect(
165165
}
166166

167167
function useEffect(
168-
create: () => mixed,
168+
create: () => (() => mixed) | null | void,
169169
inputs: Array<mixed> | void | null,
170170
): void {
171171
nextHook();

‎packages/react-dom/src/server/ReactPartialRendererHooks.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ function useRef<T>(initialValue: T): {current: T} {
264264
}
265265

266266
function useMutationEffect(
267-
create: () => mixed,
267+
create: () => (() => mixed) | null | void,
268268
inputs: Array<mixed> | void | null,
269269
) {
270270
warning(
@@ -278,7 +278,7 @@ function useMutationEffect(
278278
}
279279

280280
export function useLayoutEffect(
281-
create: () => mixed,
281+
create: () => (() => mixed) | null | void,
282282
inputs: Array<mixed> | void | null,
283283
) {
284284
warning(

‎packages/react-reconciler/src/ReactFiberHooks.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export type Hook = {
6262

6363
type Effect = {
6464
tag: HookEffectTag,
65-
create: () => mixed,
65+
create: () => (() => mixed) | null | void,
6666
destroy: (() => mixed) | null,
6767
inputs: Array<mixed>,
6868
next: Effect,
@@ -518,7 +518,7 @@ export function useRef<T>(initialValue: T): {current: T} {
518518
}
519519

520520
export function useMutationEffect(
521-
create: () => mixed,
521+
create: () => (() => mixed) | null | void,
522522
inputs: Array<mixed> | void | null,
523523
): void {
524524
useEffectImpl(
@@ -530,14 +530,14 @@ export function useMutationEffect(
530530
}
531531

532532
export function useLayoutEffect(
533-
create: () => mixed,
533+
create: () => (() => mixed) | null | void,
534534
inputs: Array<mixed> | void | null,
535535
): void {
536536
useEffectImpl(UpdateEffect, UnmountMutation | MountLayout, create, inputs);
537537
}
538538

539539
export function useEffect(
540-
create: () => mixed,
540+
create: () => (() => mixed) | null | void,
541541
inputs: Array<mixed> | void | null,
542542
): void {
543543
useEffectImpl(

‎packages/react/src/ReactHooks.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,23 @@ export function useRef<T>(initialValue: T): {current: T} {
7171
}
7272

7373
export function useEffect(
74-
create: () => mixed,
74+
create: () => (() => mixed) | null | void,
7575
inputs: Array<mixed> | void | null,
7676
) {
7777
const dispatcher = resolveDispatcher();
7878
return dispatcher.useEffect(create, inputs);
7979
}
8080

8181
export function useMutationEffect(
82-
create: () => mixed,
82+
create: () => (() => mixed) | null | void,
8383
inputs: Array<mixed> | void | null,
8484
) {
8585
const dispatcher = resolveDispatcher();
8686
return dispatcher.useMutationEffect(create, inputs);
8787
}
8888

8989
export function useLayoutEffect(
90-
create: () => mixed,
90+
create: () => (() => mixed) | null | void,
9191
inputs: Array<mixed> | void | null,
9292
) {
9393
const dispatcher = resolveDispatcher();

0 commit comments

Comments
 (0)