-
Notifications
You must be signed in to change notification settings - Fork 50.6k
Closed
Labels
Component: ESLint RulesResolution: Expected BehaviorStatus: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bug
Description
I've noticed that the "no conditional hooks" aspect of the rules-of-hooks eslint rule isn't working inside a React.memo()'ed component. The project is typescript and I'm using the parse from @typescript-eslint/parser, so I'm not sure if the problem is with the rule or with the parser.
React version:
Steps To Reproduce
- Create a component using
React.memo()inside a Typescript project - Add a hook that is called conditionally, e.g.
export const MyMemoizedComponent = React.memo((props: {}) => {
if (Math.random() > 0.5) {
React.useEffect(() => {}, []);
}
return <div />;
});Link to code example: https://codesandbox.io/s/no-rules-of-hooks-warning-in-typescript-reactmemo-ei00n?file=/src/index.tsx
The current behavior
ESLint does not show any errors.
The expected behavior
ESLint should show an error like React Hook "React.useEffect" is called conditionally. React Hooks must be called in the exact same order in every component render.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Component: ESLint RulesResolution: Expected BehaviorStatus: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bug