user15404864
user15404864

Reputation:

Reactjs How to pass parameter in onclick event in jsx

How to pass parameter using the jsx in reactjs?

this is my code

  function handleClick() {
    history.push("/home");
  }

.....

<Button 
  color="primary" 
  size="small"
  onClick={handleClick}
  className={classes.notificationbutton}>
     View
</Button>

Upvotes: 0

Views: 269

Answers (1)

Omri Attiya
Omri Attiya

Reputation: 4037

As default, onClick is passing an event parameter.

You can create arrow key function and call your handleClick there with custom parameters:

<Button 
  color="primary" 
  size="small"
  onClick={(event) => handleClick(param1, param2)}
  className={classes.notificationbutton}
>
  View
</Button>

Upvotes: 2

Related Questions