Summary
The dev-mode console.warn messages for useEffect, useInsertionEffect, and useLayoutEffect in packages/react/src/ReactHooks.js are currently vague when the create callback is null or undefined.
Current Behavior
All three hooks produce this generic message:
React Hook useEffect requires an effect callback. Did you forget to pass a callback to the hook?
This message:
- Does not distinguish between
null and undefined being passed
- Does not explain what the callback signature should look like
- Leaves beginners confused about what the correct fix is
Expected Behavior
The warning should:
- Say explicitly whether
null or undefined was received
- Explain that the hook expects a function that optionally returns a cleanup function
- Be consistent across all three effect hooks
Example improved message:
React Hook useEffect received a null effect callback. useEffect must be passed a function that optionally returns a cleanup function. Did you accidentally pass nothing or the result of a function call instead of the function itself?
Motivation
This is a very common beginner mistake — for example, passing useEffect(someAsyncFn(), []) (calling the function) instead of useEffect(someAsyncFn, []) (passing the function). A clearer error message would surface the root cause faster.
Fix
A fix has been submitted in PR #36361.
Affected Files
packages/react/src/ReactHooks.js
Summary
The dev-mode
console.warnmessages foruseEffect,useInsertionEffect, anduseLayoutEffectinpackages/react/src/ReactHooks.jsare currently vague when thecreatecallback isnullorundefined.Current Behavior
All three hooks produce this generic message:
This message:
nullandundefinedbeing passedExpected Behavior
The warning should:
nullorundefinedwas receivedExample improved message:
Motivation
This is a very common beginner mistake — for example, passing
useEffect(someAsyncFn(), [])(calling the function) instead ofuseEffect(someAsyncFn, [])(passing the function). A clearer error message would surface the root cause faster.Fix
A fix has been submitted in PR #36361.
Affected Files
packages/react/src/ReactHooks.js