Skip to content

Commit 0fca22a

Browse files
committed
[lint] treat React.use() the same as use()
1 parent f4bf78a commit 0fca22a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,12 @@ const tests = {
489489
},
490490
{
491491
code: normalizeIndent`
492+
import * as React from 'react';
492493
function App() {
493494
if (shouldShowText) {
494495
const text = use(query);
496+
const data = React.use(thing);
497+
const data2 = react.use(thing2);
495498
return <Text text={text} />
496499
}
497500
return <Text text={shouldFetchBackupText ? use(backupQuery) : "Nothing to see here"} />

packages/eslint-plugin-react-hooks/src/RulesOfHooks.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,17 @@ function isUseEffectEventIdentifier(node) {
108108
}
109109

110110
function isUseIdentifier(node) {
111-
return node.type === 'Identifier' && node.name === 'use';
111+
switch (node.type) {
112+
case 'Identifier':
113+
return node.name === 'use';
114+
case 'MemberExpression':
115+
return (
116+
(node.object.name === 'React' || node.object.name === 'react') &&
117+
node.property.name === 'use'
118+
);
119+
default:
120+
return false;
121+
}
112122
}
113123

114124
export default {

0 commit comments

Comments
 (0)