How to use the onClick event on react Link component?

advertisements

I am using the Link component from the reactjs router and I cannot get the onClickevent working. This is the code:

<Link to={this.props.myroute} onClick='hello()'>Here</Link>

Is this the way to do it or another way?


You are passing hello() as a string, also hello() means execute hello immediately.

try

onClick={hello}