Skip to content

Commit

Permalink
[lint] treat React.use() the same as use() (facebook#27769)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kassens authored and AndyPengc12 committed Apr 15, 2024
1 parent bd779fa commit e2e9e9e
Show file tree
Hide file tree
Showing 2 changed files with 4 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
2 changes: 1 addition & 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,7 @@ function isUseEffectEventIdentifier(node) {
}

function isUseIdentifier(node) {
return node.type === 'Identifier' && node.name === 'use';
return isReactFunction(node, 'use');
}

export default {
Expand Down

0 comments on commit e2e9e9e

Please sign in to comment.