jsx-handler-names
Configuration
Rule Details
Enforce event handler naming conventions in JSX. This rule ensures that any component or prop methods used to handle events are correctly prefixed.
By default, event handler functions must be named handleX (camelCase, beginning with handle), and props that receive event handlers must be named onX (camelCase, beginning with on).
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Rule Options
eventHandlerPrefix: Prefix for component methods used as event handlers. Defaults tohandle. Set tofalseto disable handler-name checks.eventHandlerPropPrefix: Prefix for props that are used as event handlers. Defaults toon. Set tofalseto disable prop-key checks.checkLocalVariables: Determines whether event handlers stored as local variables are checked. Defaults tofalse.checkInlineFunction: Determines whether event handlers set as inline functions are checked. Defaults tofalse.ignoreComponentNames: Array of glob strings, when matched with component name, ignores the rule on that component. Defaults to[]. Supports namespaced component names (e.g.,A.TestComponent,A.MyLib*).
Examples of incorrect code for this rule with { "checkLocalVariables": true }:
Examples of correct code for this rule with { "checkLocalVariables": true }:
Examples of incorrect code for this rule with { "checkInlineFunction": true }:
Examples of correct code for this rule with { "checkInlineFunction": true }:
Examples of correct code for this rule with { "ignoreComponentNames": ["MyLib*"] }:
When Not To Use It
If you are not using JSX, or if you don't want to enforce specific naming conventions for event handlers.