Skip to content

Commit e2e9e9e

Browse files
kassensAndyPengc12
authored andcommitted
[lint] treat React.use() the same as use() (facebook#27769)
We should probably treat `React.use()` the same as `use()` to allow it within loops and conditionals. Ideally this would implement a test that `React` is imported or required from `'react'`, but we don't otherwise implement such a test.
1 parent bd779fa commit e2e9e9e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function isUseEffectEventIdentifier(node) {
108108
}
109109

110110
function isUseIdentifier(node) {
111-
return node.type === 'Identifier' && node.name === 'use';
111+
return isReactFunction(node, 'use');
112112
}
113113

114114
export default {

0 commit comments

Comments
 (0)