File tree 2 files changed +21
-31
lines changed
packages/eslint-plugin-react-hooks 2 files changed +21
-31
lines changed Original file line number Diff line number Diff line change @@ -550,21 +550,6 @@ const tests = {
550
550
// TODO: this should error but doesn't.
551
551
// errors: [genericError('useState')],
552
552
} ,
553
- {
554
- code : normalizeIndent `
555
- async function Page() {
556
- useId();
557
- React.useId();
558
- }
559
- ` ,
560
- } ,
561
- {
562
- code : normalizeIndent `
563
- async function useAsyncHook() {
564
- useId();
565
- }
566
- ` ,
567
- } ,
568
553
] ,
569
554
invalid : [
570
555
{
@@ -1144,6 +1129,26 @@ const tests = {
1144
1129
` ,
1145
1130
errors : [ asyncComponentHookError ( 'useState' ) ] ,
1146
1131
} ,
1132
+ {
1133
+ code : normalizeIndent `
1134
+ async function Page() {
1135
+ useId();
1136
+ React.useId();
1137
+ }
1138
+ ` ,
1139
+ errors : [
1140
+ asyncComponentHookError ( 'useId' ) ,
1141
+ asyncComponentHookError ( 'React.useId' ) ,
1142
+ ] ,
1143
+ } ,
1144
+ {
1145
+ code : normalizeIndent `
1146
+ async function useAsyncHook() {
1147
+ useId();
1148
+ }
1149
+ ` ,
1150
+ errors : [ asyncComponentHookError ( 'useId' ) ] ,
1151
+ } ,
1147
1152
{
1148
1153
code : normalizeIndent `
1149
1154
async function notAHook() {
Original file line number Diff line number Diff line change @@ -40,21 +40,6 @@ function isHook(node) {
40
40
}
41
41
}
42
42
43
- const serverComponentHooks = new Set ( [ 'useId' ] ) ;
44
- function isServerComponentHook ( node ) {
45
- if ( node . type === 'Identifier' ) {
46
- return serverComponentHooks . has ( node . name ) ;
47
- } else if (
48
- node . type === 'MemberExpression' &&
49
- ! node . computed &&
50
- node . property . type === 'Identifier'
51
- ) {
52
- return serverComponentHooks . has ( node . property . name ) ;
53
- } else {
54
- return false ;
55
- }
56
- }
57
-
58
43
/**
59
44
* Checks if the node is a React component name. React component names must
60
45
* always start with an uppercase letter.
@@ -519,7 +504,7 @@ export default {
519
504
if ( isDirectlyInsideComponentOrHook ) {
520
505
// Report an error if the hook is called inside an async function.
521
506
const isAsyncFunction = codePathNode . async ;
522
- if ( isAsyncFunction && ! isServerComponentHook ( hook ) ) {
507
+ if ( isAsyncFunction ) {
523
508
context . report ( {
524
509
node : hook ,
525
510
message :
You can’t perform that action at this time.
0 commit comments