React - FAQ

Updated: 2018-12-09

How to pass parameter in event handler

Suppose handleClick() is a function, in events like onClick, the function name, WITHOUT parenthesis, should be passed.

<button onClick={this.handleClick} />

Otherwise if it is passed liked this

<button onClick={this.handleClick()} />

The function will be executed everything the render() is called, and the button onClick would not be working.

To pass parameters in the function, you have to create another function to wrap around it:

<button onClick={() => this.handleClick(id)} />

Why google is not defined

When using google maps and other APIs.

Add /*global google*/ to the top of the page

Why css is not working by assigning class

use className instead of class in JSX