Skip to content

Commit

Permalink
[ESLint] Disallow hooks in async functions (#27045)
Browse files Browse the repository at this point in the history
Hooks cannot be called in async functions, on either the client or the
server. This mistake sometimes happens when using Server Components,
especially when refactoring a Server Component to a Client Component.

React logs a warning at runtime, but it's even better to catch this with
a lint rule since it will show immediate inline feedback in the editor.

I added this to the existing "Rules of Hooks" ESLint rule.

DiffTrain build for commit 7118f5d.
  • Loading branch information
acdlite committed Jul 5, 2023
1 parent 3a55239 commit 9a8a80b
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23982,7 +23982,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-canary-035a41c4e-20230704";
var ReactVersion = "18.3.0-canary-7118f5dd7-20230705";

// Might add PROFILE later.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8630,7 +8630,7 @@ var devToolsConfig$jscomp$inline_1032 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-035a41c4e-20230704",
version: "18.3.0-canary-7118f5dd7-20230705",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1231 = {
Expand Down Expand Up @@ -8661,7 +8661,7 @@ var internals$jscomp$inline_1231 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-035a41c4e-20230704"
reconcilerVersion: "18.3.0-canary-7118f5dd7-20230705"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1232 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9056,7 +9056,7 @@ var devToolsConfig$jscomp$inline_1074 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-035a41c4e-20230704",
version: "18.3.0-canary-7118f5dd7-20230705",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1272 = {
Expand Down Expand Up @@ -9087,7 +9087,7 @@ var internals$jscomp$inline_1272 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-035a41c4e-20230704"
reconcilerVersion: "18.3.0-canary-7118f5dd7-20230705"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1273 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-canary-035a41c4e-20230704";
var ReactVersion = "18.3.0-canary-7118f5dd7-20230705";

// ATTENTION
// When adding new symbols to this file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,4 +623,4 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-canary-035a41c4e-20230704";
exports.version = "18.3.0-canary-7118f5dd7-20230705";
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-canary-035a41c4e-20230704";
exports.version = "18.3.0-canary-7118f5dd7-20230705";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
035a41c4e2aadad8f8826396940af404e87dd772
7118f5dd7bf5f1c44d0d2944ef8ad58e423909ad

0 comments on commit 9a8a80b

Please sign in to comment.