Gelio / tslint-react-hooks

TSLint rule for detecting invalid uses of React Hooks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

extend supported component decorators

mbest opened this issue Β· comments

Currently only React.forwardRef and React.memo are supported. If using Mobx-React, the observer HOC triggers this error and requires overrides in the file. It would be good if we could add observer to the allowed list.

Hey @mbest, thanks for reporting this πŸ‘

It seems like a valid use case to be able to allow this. However, I'd like to make the rule more lenient by default - not everyone may use the observer function from MobX.

Thus, I suggest making it opt-in by exposing a configurable list of function names that should be treated as HOCs.

I am quite busy with my university at the moment, so it may take a while for me to add this functionality. If you (or anyone else) have some spare time, feel free to raise an MR πŸ˜„

I realized that I can work around the rule by giving the inner function a component-style name:

export const WebsiteFilterToggle = observer(function WebsiteFilterToggle() {
    const [state, setstate] = useState(initialState);
    ...
});

Still, I'll look into submitting a PR for configurable HOCs.

Oh, right, I forgot to mention that workaround πŸ˜„ Good catch

Thanks for mentioning it πŸ‘