Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react/jsx-handler-names should not flag arrow functions #2586

Closed
astorije opened this issue Mar 6, 2020 · 6 comments · Fixed by #2761
Closed

react/jsx-handler-names should not flag arrow functions #2586

astorije opened this issue Mar 6, 2020 · 6 comments · Fixed by #2761

Comments

@astorije
Copy link

astorije commented Mar 6, 2020

Given the following configuration:

react/jsx-handler-names:
  - error
  - eventHandlerPrefix: '(handle|on|set)'
    checkLocalVariables: true

The following code:

<Button onClick={() => setVisible(!visible)}>
  {visible ? 'Hide' : 'Show'}
</Button>

fails linting with the following message:

Handler function for onClick prop key must begin with '(handle|on|set)'  react/jsx-handler-names

We believe react/jsx-handler-names should not trigger on arrow functions, because there is no way to address the handler naming violation without refactoring into a variable or similar (which, while probably valid, is another rule/problem).
Thoughts?

@ljharb
Copy link
Member

ljharb commented Mar 6, 2020

At the least, that seems like a reasonable option to add.

@aaronetto
Copy link

I agree with this correction because it would help a lot to work with react hooks.

@dididy
Copy link
Contributor

dididy commented Aug 2, 2020

Could I resolve this issue? I'm working on it.

@ljharb
Copy link
Member

ljharb commented Aug 2, 2020

@dididy yes, anything with the "help wanted" label that doesn't already have a linked PR is up for grabs :-)

@roshcagra
Copy link

Any update on this? Glad to help!

@dididy
Copy link
Contributor

dididy commented Aug 24, 2020

@ljharb @roshcagra Could you review my Pull Request? #2761

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

5 participants