Skip to content

Commit

Permalink
[lint] treat React.use() the same as use()
Browse files Browse the repository at this point in the history
  • Loading branch information
kassens committed Nov 30, 2023
1 parent b8be034 commit 790aab0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,12 @@ const tests = {
},
{
code: normalizeIndent`
import * as React from 'react';
function App() {
if (shouldShowText) {
const text = use(query);
const data = React.use(thing);
const data2 = react.use(thing2);
return <Text text={text} />
}
return <Text text={shouldFetchBackupText ? use(backupQuery) : "Nothing to see here"} />
Expand Down
12 changes: 11 additions & 1 deletion packages/eslint-plugin-react-hooks/src/RulesOfHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,17 @@ function isUseEffectEventIdentifier(node) {
}

function isUseIdentifier(node) {
return node.type === 'Identifier' && node.name === 'use';
switch (node.type) {
case 'Identifier':
return node.name === 'use';
case 'MemberExpression':
return (
(node.object.name === 'React' || node.object.name === 'react') &&
node.property.name === 'use'
);
default:
return false;
}
}

export default {
Expand Down

0 comments on commit 790aab0

Please sign in to comment.