Skip to main content
InterviewHubPRO
Section Overview
Q333

Question 333 of 407

Part 9: React Hooks Deep Dive (262 - 316)

82%
React Core & Hooks (407 Qs)•Part 9: React Hooks Deep Dive (262 - 316)

What would be the common mistake of function being called every time the component renders?

mid LevelCode ExampleComponentsHooks

You need to make sure that function is not being called while passing the function as a parameter.

jsx
    render() {
      // Wrong: handleClick is called instead of passed as a reference!
      return <button onClick={this.handleClick()}>{'Click Me'}</button>
    }
sql
Instead, pass the function itself without parenthesis:
jsx
    render() {
      // Correct: handleClick is passed as a reference!
      return <button onClick={this.handleClick}>{'Click Me'}</button>
    }