-
Notifications
You must be signed in to change notification settings - Fork 50k
Closed
Closed
Copy link
Labels
Description
Normally if you use a custom hook from anywhere other than a top-level function component, you get a lint error. However, if the custom hook is imported with a namespace import, you don't see a lint error. It's worth mentioning, I'm using typescript, I'm not sure if this repros with regular JS.
React version: We use 16.9, but the create-react-app repro below is with ^16.13.1. It repros with the latest hooks plugin (3.0.0), as well as 2.3.0.
Steps To Reproduce
- npx create-react-app namespacerepro --template typescript
- Add a new file Hooks.tsx
import React from 'react';
export function useHook(): string {
const [state] = React.useState("foo");
return state;
}- Update App.tsx as following:
import React from 'react';
import logo from './logo.svg';
import './App.css';
import * as Hooks from './Hooks';
function App() {
const text = otherFunction();
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
{text}
</a>
</header>
</div>
);
}
function otherFunction(): string {
return Hooks.useHook();
}
export default App;The current behavior
No lint error shown.
The expected behavior
Lint error is shown only if changing:
- Hook import to
import * as Hooks from './Hooks'; - Hook call to
return useHook();