@samitouri / QOS-React-1 / commits / 640ccebb7d

[lint] treat React.use() the same as use() (#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.

Jan Kassens committed Dec 1, 2023 at 15:02 UTC 640ccebb7d9669f1efbd20e86f6f84086c3d698d
2 files changed +4 -1
packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js
+3
@@ -489,9 +489,12 @@ const tests = {
489 },
490 {
491 code: normalizeIndent`
492 + import * as React from 'react';
493 function App() {
494 if (shouldShowText) {
495 const text = use(query);
496 + const data = React.use(thing);
497 + const data2 = react.use(thing2);
498 return <Text text={text} />
499 }
500 return <Text text={shouldFetchBackupText ? use(backupQuery) : "Nothing to see here"} />
packages/eslint-plugin-react-hooks/src/RulesOfHooks.js
+1 -1
@@ -108,7 +108,7 @@ function isUseEffectEventIdentifier(node) {
108 }
109
110 function isUseIdentifier(node) {
111 - return node.type === 'Identifier' && node.name === 'use';
111 + return isReactFunction(node, 'use');
112 }
113
114 export default {