Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
63
rated 0 times [  70] [ 7]  / answers: 1 / hits: 26000  / 4 Years ago, mon, february 3, 2020, 12:00:00

I believe keeping code consistent is kind of important stuff.
Sometimes I mess my code with different handler names (working with Javascript).
What is the right name for event handlers? onClick vs handleClick?


More From » reactjs

 Answers
67

This is subjective, but what you would see the most is the following:




  • if you are creating component and exposing event hooks, those props would be on: onClick, onHover, onUsernameChanged, onError. From inside your components, these props are just functions you call on some event. You don't care what they do, your job is to just call them at the right time

  • if you are consuming another component, you want to add handling in response to these events, so you use handle: handleChange, handleClick, handleUserLogout, because your job is now to handle some event and make something happen in response to it. If you don't handle, no changes to the app state will be made


[#51246] Sunday, January 26, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
briannar

Total Points: 354
Total Questions: 103
Total Answers: 101

Location: Japan
Member since Sat, Jun 6, 2020
4 Years ago
;