Gelio / tslint-react-hooks

TSLint rule for detecting invalid uses of React Hooks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not warning about custom hooks as properties

esamattis opened this issue · comments

This should warn

if (cond) {
    MyHooks.useHook();
}

like this does

if (cond) {
    React.useEffect();
}

This is a deliberate decision from eslint-plugin-react-hooks to prevent false positives

If you import the function and use it directly then it will work

import { useHook } from 'MyHooks';

if (cond) {
  useHook(); // This will have a warning
}

And if you check the docs, they tend to do this with the default hooks too, rather than using e.g. React.useEffect()

@CruseCtrl Thank you for the explanation.

When implementing this rule, I strictly followed each heuristic that was made in eslint-plugin-react-hooks. Detecting using namespaced hooks is one of them.

If the eslint plugin changes this logic, I will try to update this project accordingly 🙂 For now, I am closing this issue to keep the behavior as is, matching the original rule