Reputation: 615
Here is the code for the back button I'm trying to include at the top of my page:
<a onClick={this.goBack()}>Go back</a>
And here is the helper function goBack():
goBack(){
return history.go(-1);
}
I've also tried this, which produces the same result:
<a href={this.goBack()}>Go back</a>
I'm new to the history method, so any clarification would be much appreciated! Thanks
Upvotes: 0
Views: 49
Reputation: 42520
this.goBack()
immediately executes function this.goBack
.
Instead, only assign the function as an event handler by removing the brackets ()
:
<a onClick={this.goBack}>Go back</a>
Upvotes: 1