react/jsx-handler-names: cannot opt-out of handler prefix independent of prop prefix
See original GitHub issueIssue
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';
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].*$`);
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Awesome; will see if I can give it a shot in the coming week.
Thanks. Adding support for
false
- in either config option, but not both - seems like a great PR.