question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react/jsx-handler-names: cannot opt-out of handler prefix independent of prop prefix

See original GitHub issue

Issue

I only want to enforce eventHandlerPropPrefix, but I cannot selectively opt out of eventHandlerPrefix.


1. Rule always plugs in a default value ‘handle’ into eventHandlerPrefix when supplied value is an empty string '' (falsy)

Problematic code:

// will always be set to 'handle' when falsy
const eventHandlerPrefix = configuration.eventHandlerPrefix || 'handle';

source


2. Rule prevents “whitelist” JS regex workarounds noted in #1687 because a capital letter must succeed the allowed prefix.

Example Config: I want to whitelist submit select verbatim and handle* prefix:

"react/jsx-handler-names": ['error', {
  "eventHandlerPrefix": '(handle|submit|select)',
  "eventHandlerPropPrefix": 'on',
}],

Problematic code:

// [A-Z] succeeding eventHandlerPrefix prevents handler whitelist
const EVENT_HANDLER_REGEX = new RegExp(`^((props\\.${eventHandlerPropPrefix})|((.*\\.)?${eventHandlerPrefix}))[A-Z].*$`);

source

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
drewlustrocommented, Sep 6, 2019

Awesome; will see if I can give it a shot in the coming week.

1reaction
ljharbcommented, Sep 6, 2019

Thanks. Adding support for false - in either config option, but not both - seems like a great PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react/jsx-handler-names: cannot opt-out of handler prefix ...
I only want to enforce eventHandlerPropPrefix , but I cannot selectively opt out of eventHandlerPrefix . 1. Rule always plugs in a default...
Read more >
Developers - react/jsx-handler-names: cannot opt-out of ...
I only want to enforce eventHandlerPropPrefix , but I cannot selectively opt out of eventHandlerPrefix . 1. Rule always plugs in a default...
Read more >
Hooks FAQ - React
Do Hooks cover all use cases for classes? Do Hooks replace render props and higher-order components? What do Hooks mean for popular APIs...
Read more >
Event Handler Naming in React - Jake Trent
When defining the prop names, I usually prefix with on* , as in onClick . This matches the built-in event handler convention.
Read more >
How To Use Styled-Components In React - Smashing Magazine
Styled components are independent of each other, and you do not have to worry about their names because the library handles that for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found