From 640ccebb7d9669f1efbd20e86f6f84086c3d698d Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Fri, 1 Dec 2023 15:02:11 -0500 Subject: [PATCH] [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. --- .../__tests__/ESLintRulesOfHooks-test.js | 3 +++ packages/eslint-plugin-react-hooks/src/RulesOfHooks.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js b/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js index 260829d8ad..f392cf6198 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js +++ b/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js @@ -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 } return diff --git a/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js b/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js index 660d92f9ea..bdc23f9f88 100644 --- a/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js +++ b/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js @@ -108,7 +108,7 @@ function isUseEffectEventIdentifier(node) { } function isUseIdentifier(node) { - return node.type === 'Identifier' && node.name === 'use'; + return isReactFunction(node, 'use'); } export default {