Bug: [eslint-plugin-react-hooks] RuleOfHooks does not find conditional hook if HOC (e.g. mobx "observer") applied directly
See original GitHub issueReact version: 16.13.1
Steps To Reproduce
- Create a component using a conditional hook
- Wrap the component with a HOC, e.g. mobx observer
Example
function HOC<T>(c: T): T { return c; }
const ConditionalHookComp = HOC(
({ flag }): JSX.Element => {
if (flag) {
useEffect(() => console.log("something"));
}
return <></>;
});
The current behavior
The linter does not issue a warning/error for the conditional use of hooks, unless you remove the HOC.
The expected behavior
The linter issues a warning/error for the conditional use of hooks regardless whether the component is wrapped by an HOC or not.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
Why eslint-plugin-react-hooks doesn't warn when using react ...
If I use hooks conditionally in custom hooks, there will be a warning like this: "React Hook \"useState\" is called conditionally. React Hooks...
Read more >Understanding common frustrations with React Hooks
Let's go over some of these common error messages in React Hooks and discuss why they occur. “React Hook cannot be called inside...
Read more >README · MobX
The observer wrapper around the TimerView React component will automatically detect that rendering depends on the timer.secondsPassed observable, even though ...
Read more >mobx-react | Yarn - Package Manager
Package with React component wrapper for combining React with MobX. Exports the observer decorator and other utilities. For documentation, see the MobX ......
Read more >mobx-react - npm
The simple rule of thumb is: all components that render observable data. If you don't want to mark a component as observer, for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
is not an unnamed function (
console.log(ConditionalHookComp.name); // "ConditionalHookComp"
).You are right, my mistake, name is inferred. We will probably need to follow some pattern for the observer HOC in our project if we want the linter support. Thank you for your support!