Skip to content

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

Closed
@astorije

Description

@astorije

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions