Javascript: Explicitly clarify naming policy for React event handler methods

Created on 2 Dec 2015  Â·  5Comments  Â·  Source: airbnb/javascript

The ordering section implies that event handlers should be named onFoo rather than handleFoo per FB examples. Is this an explicit rule? If so, it would be nice to have it listed in either the "naming" or "methods" sections.

question

Most helpful comment

I'm wondering if there's been any changes here – onFoo, handleFoo, "use an appropriate verb-based clause", or something else, especially given that the rule set still includes sort-comp.

All 5 comments

Any update?

It's worth noting this was briefly discussed in this PR: https://github.com/airbnb/javascript/pull/619

Interesting – I think it makes sense to name handlers according to what they do, though; makes it easier to see at a glance what is going on without having to check render(). In other words,

class PokePlayerButton extends React.Component {
  /* ... */

  onClick() {
    this.props.pokePlayer();
  }

  /* ... */
}

Otherwise it's harder to tell what's actually the click handler without looking at the source of render().

I'm wondering if there's been any changes here – onFoo, handleFoo, "use an appropriate verb-based clause", or something else, especially given that the rule set still includes sort-comp.

Any updates here?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ar
mbifulco picture mbifulco  Â·  3Comments

danielfttorres picture danielfttorres  Â·  3Comments

zurfyx picture zurfyx  Â·  3Comments

progre picture progre  Â·  3Comments

weihongyu12 picture weihongyu12  Â·  3Comments