Naming Functions in React Components #1727
Replies: 3 comments
-
Hello, I'm Abdone, How can I contribute to this |
Beta Was this translation helpful? Give feedback.
-
I connect with this proposal since I’ve often had to dig into implementations just to understand a function’s role. Clear naming rules would remove that friction, improve readability, and make collaboration smoother. I’d love to contribute to this effort—how can I get started or be part of the contribution process? |
Beta Was this translation helpful? Give feedback.
-
Hello, I’m new to this community and interested in contributing. I want to be part of this platform to improve my skills, learn open-source collaboration, and contribute to meaningful projects. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Motivation
As the codebase scales, clarity in function naming becomes essential. Event handlers and internal logic functions inside components are frequently read and modified, so their names should communicate intent without requiring the reader to look at the implementation.
This RFC proposes guidelines to improve naming consistency and reduce ambiguity in component logic.
Problem Statement
Here’s a typical (but problematic) example:
Issues:
onSubmitClick
andhandleClose
provide little insight into what actually happens.on
,handle
) add noise rather than clarity.Proposed Naming Rules
✅ Do
❌ Don’t
on
,handle
, ordo
.Examples
❌ Before
✅ After
Now the JSX reads more like a sentence:
"onClick validate and save"
— makes sense immediately."onClick close modal"
— specific and predictable.Rule Summary Table
validateAndSave
onSubmitClick
,handleSubmit
closeModal
handleClose
,doClose
uploadProfileImage
onImageChange
,handleUploadClick
submitReview
handleReviewSubmit
Application Scope
This rule applies to all functions declared inside components, especially:
onClick
,onChange
, etc.)Third-party integration handlers (e.g. libraries like Formik or React Hook Form) may still require conventional names (e.g.
handleSubmit
) when bound to external APIs — use good judgment.Migration Plan
Open Questions
Conclusion
Clarity scales. By giving functions meaningful names, we:
Beta Was this translation helpful? Give feedback.
All reactions