Qasim Rizvi
Qasim Rizvi

Reputation: 131

Is it Good Practice to use return in onClick in ReactJS?

On one of my PRs, my colleague comment to use return before these functions call is it a good practice to use return in onClick.

Note: these functions do not return anything.

onClick={() => {
  if (isPlatform) {
    handlePlatformChange({ selectedPlatform: item, selectedTab: index });
  } else if (isExecution) {
    handleExecutionMode(item);
  } else {
    handleBrowserChange([item], index);
  }
 }}

Upvotes: 1

Views: 25

Answers (1)

JeromeBu
JeromeBu

Reputation: 1159

I don't believe there is any problem with returning in onClick.

I do agree that it would be more convenient to read if you would return.

For example : 

onClick={() => {
  if (isPlatform) {
    return handlePlatformChange({ selectedPlatform: item, selectedTab: index });
  }
  if (isExecution) return handleExecutionMode(item);
  return handleBrowserChange([item], index);
 }
}

Upvotes: 2

Related Questions