Gelio / tslint-react-hooks

TSLint rule for detecting invalid uses of React Hooks
MIT License
218 stars 10 forks source link

Doesn't work with React.memo or React.forwardRef (maybe others) #2

Closed nervestaple closed 5 years ago

nervestaple commented 5 years ago

I'm getting A hook cannot be used inside of another function [react-hooks-nesting] triggered on components wrapped in React.memo() and React.forwardRef()

Gelio commented 5 years ago

Good point 👍 Thanks for pointing that out. I will try to fix it in the nearest future.

In the meantime, you can either disable the rule for a specific line or split the declaration of the inner component and the wrapped component into two.

For example,

const WrappedComponent = React.memo((props) => (<div>Hello World</div>));

would become:

const InnerComponent = (props) => (<div>Hello World</div>);
const WrappedComponent = React.memo(InnerComponent);

Then, the hooks should be verified correctly.

nervestaple commented 5 years ago

Nice! Good idea.

Gelio commented 5 years ago

Yesterday I released tslint-react-hooks@1.1.0 which should fix this problem 😄

@nervestaple Could you take a look and verify that the new release solves it for you? If so, then this issue could be closed

nervestaple commented 5 years ago

looks good! thanks!