Skip to content

Commit 5d67cb7

Browse files
committed
Added dev-only warning for null/undefined create in use*Effect (#32355)
## Summary Fixes #32354. Re-creation of #15197: adds a dev-only warning if `create == null` to the three `use*Effect` functions: * `useEffect` * `useInsertionEffect` * `useLayoutEffect` Updates the warning to match the same text given in the `react/exhaustive-deps` lint rule. ## How did you test this change? I applied the changes manually within `node_modules/` on a local clone of https://github.com/JoshuaKGoldberg/repros/tree/react-use-effect-no-arguments. Please pardon me for opening a PR addressing a not-accepted issue. I was excited to get back to #15194 -> #15197 now that I have time. 🙂 --------- Co-authored-by: lauren <[email protected]> DiffTrain build for [192555b](192555b)
1 parent 1622d0f commit 5d67cb7

35 files changed

+113
-86
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a69b80d07e5d1bf363ed15d6209a55b35e0765c2
1+
192555bb0ed88db30f91c58651c421f178f90384
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a69b80d07e5d1bf363ed15d6209a55b35e0765c2
1+
192555bb0ed88db30f91c58651c421f178f90384

compiled/facebook-www/React-dev.classic.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,10 @@ __DEV__ &&
19151915
updateDeps,
19161916
destroy
19171917
) {
1918+
null == create &&
1919+
warn(
1920+
"React Hook useEffect requires an effect callback. Did you forget to pass a callback to the hook?"
1921+
);
19181922
var dispatcher = resolveDispatcher();
19191923
if (
19201924
enableUseEffectCRUDOverload &&
@@ -1940,9 +1944,17 @@ __DEV__ &&
19401944
return resolveDispatcher().useImperativeHandle(ref, create, deps);
19411945
};
19421946
exports.useInsertionEffect = function (create, deps) {
1947+
null == create &&
1948+
warn(
1949+
"React Hook useInsertionEffect requires an effect callback. Did you forget to pass a callback to the hook?"
1950+
);
19431951
return resolveDispatcher().useInsertionEffect(create, deps);
19441952
};
19451953
exports.useLayoutEffect = function (create, deps) {
1954+
null == create &&
1955+
warn(
1956+
"React Hook useLayoutEffect requires an effect callback. Did you forget to pass a callback to the hook?"
1957+
);
19461958
return resolveDispatcher().useLayoutEffect(create, deps);
19471959
};
19481960
exports.useMemo = function (create, deps) {
@@ -1974,7 +1986,7 @@ __DEV__ &&
19741986
exports.useTransition = function () {
19751987
return resolveDispatcher().useTransition();
19761988
};
1977-
exports.version = "19.1.0-www-classic-a69b80d0-20250211";
1989+
exports.version = "19.1.0-www-classic-192555bb-20250211";
19781990
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
19791991
"function" ===
19801992
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-dev.modern.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,10 @@ __DEV__ &&
19151915
updateDeps,
19161916
destroy
19171917
) {
1918+
null == create &&
1919+
warn(
1920+
"React Hook useEffect requires an effect callback. Did you forget to pass a callback to the hook?"
1921+
);
19181922
var dispatcher = resolveDispatcher();
19191923
if (
19201924
enableUseEffectCRUDOverload &&
@@ -1940,9 +1944,17 @@ __DEV__ &&
19401944
return resolveDispatcher().useImperativeHandle(ref, create, deps);
19411945
};
19421946
exports.useInsertionEffect = function (create, deps) {
1947+
null == create &&
1948+
warn(
1949+
"React Hook useInsertionEffect requires an effect callback. Did you forget to pass a callback to the hook?"
1950+
);
19431951
return resolveDispatcher().useInsertionEffect(create, deps);
19441952
};
19451953
exports.useLayoutEffect = function (create, deps) {
1954+
null == create &&
1955+
warn(
1956+
"React Hook useLayoutEffect requires an effect callback. Did you forget to pass a callback to the hook?"
1957+
);
19461958
return resolveDispatcher().useLayoutEffect(create, deps);
19471959
};
19481960
exports.useMemo = function (create, deps) {
@@ -1974,7 +1986,7 @@ __DEV__ &&
19741986
exports.useTransition = function () {
19751987
return resolveDispatcher().useTransition();
19761988
};
1977-
exports.version = "19.1.0-www-modern-a69b80d0-20250211";
1989+
exports.version = "19.1.0-www-modern-192555bb-20250211";
19781990
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
19791991
"function" ===
19801992
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-prod.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,4 +641,4 @@ exports.useSyncExternalStore = function (
641641
exports.useTransition = function () {
642642
return ReactSharedInternals.H.useTransition();
643643
};
644-
exports.version = "19.1.0-www-classic-a69b80d0-20250211";
644+
exports.version = "19.1.0-www-classic-192555bb-20250211";

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,4 +641,4 @@ exports.useSyncExternalStore = function (
641641
exports.useTransition = function () {
642642
return ReactSharedInternals.H.useTransition();
643643
};
644-
exports.version = "19.1.0-www-modern-a69b80d0-20250211";
644+
exports.version = "19.1.0-www-modern-192555bb-20250211";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ exports.useSyncExternalStore = function (
645645
exports.useTransition = function () {
646646
return ReactSharedInternals.H.useTransition();
647647
};
648-
exports.version = "19.1.0-www-classic-a69b80d0-20250211";
648+
exports.version = "19.1.0-www-classic-192555bb-20250211";
649649
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
650650
"function" ===
651651
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ exports.useSyncExternalStore = function (
645645
exports.useTransition = function () {
646646
return ReactSharedInternals.H.useTransition();
647647
};
648-
exports.version = "19.1.0-www-modern-a69b80d0-20250211";
648+
exports.version = "19.1.0-www-modern-192555bb-20250211";
649649
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
650650
"function" ===
651651
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/ReactART-dev.classic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17397,10 +17397,10 @@ __DEV__ &&
1739717397
(function () {
1739817398
var internals = {
1739917399
bundleType: 1,
17400-
version: "19.1.0-www-classic-a69b80d0-20250211",
17400+
version: "19.1.0-www-classic-192555bb-20250211",
1740117401
rendererPackageName: "react-art",
1740217402
currentDispatcherRef: ReactSharedInternals,
17403-
reconcilerVersion: "19.1.0-www-classic-a69b80d0-20250211"
17403+
reconcilerVersion: "19.1.0-www-classic-192555bb-20250211"
1740417404
};
1740517405
internals.overrideHookState = overrideHookState;
1740617406
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -17434,7 +17434,7 @@ __DEV__ &&
1743417434
exports.Shape = Shape;
1743517435
exports.Surface = Surface;
1743617436
exports.Text = Text;
17437-
exports.version = "19.1.0-www-classic-a69b80d0-20250211";
17437+
exports.version = "19.1.0-www-classic-192555bb-20250211";
1743817438
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1743917439
"function" ===
1744017440
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/ReactART-dev.modern.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17169,10 +17169,10 @@ __DEV__ &&
1716917169
(function () {
1717017170
var internals = {
1717117171
bundleType: 1,
17172-
version: "19.1.0-www-modern-a69b80d0-20250211",
17172+
version: "19.1.0-www-modern-192555bb-20250211",
1717317173
rendererPackageName: "react-art",
1717417174
currentDispatcherRef: ReactSharedInternals,
17175-
reconcilerVersion: "19.1.0-www-modern-a69b80d0-20250211"
17175+
reconcilerVersion: "19.1.0-www-modern-192555bb-20250211"
1717617176
};
1717717177
internals.overrideHookState = overrideHookState;
1717817178
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -17206,7 +17206,7 @@ __DEV__ &&
1720617206
exports.Shape = Shape;
1720717207
exports.Surface = Surface;
1720817208
exports.Text = Text;
17209-
exports.version = "19.1.0-www-modern-a69b80d0-20250211";
17209+
exports.version = "19.1.0-www-modern-192555bb-20250211";
1721017210
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1721117211
"function" ===
1721217212
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)