Pranesh Ravi
Pranesh Ravi

Reputation: 33

Naming conventions in ReactJs

Is it good to have the function name same as the event listeners?

Example:

function onClick: function(event){
//body
}

<div class="example" onClick={this.onClick} /> 

Upvotes: 1

Views: 1840

Answers (1)

EntGriff
EntGriff

Reputation: 875

It does not matter what coding language you use, the name of a function should be as informative as possible. A function name like onClick does not describe what the function does. If you want to call this function from another place the name onClick would not help you understand the purpose of the function. You would have to view the code to understand it.

It would be better to be more descriptive and call it something like this :

  1. sendPrivateMessage()
  2. clientAddress
  3. doSomething()

The name you choose depends on what this function does.

If you are interested in "clean code standards" I think this is the best book about clean coding and naming standards : clean code

Upvotes: 2

Related Questions