I want to create a React component with a render method that has an <a>
tag that wraps an entire "box", if you will, which redirects to another page when clicked. Within said box there is a <button>
that can be clicked that activates an event that changes state.
What I want to be able to do is click the <button>
and trigger the event without the redirect from the <a>
tag occurring.
Tried some ideas with stopPropagation() but no luck :/ I don't want to move the button outside of the <a>
tag either so not sure where to go from here.
It seems like it should be something simple but I just can't figure it out. Thanks!
the render method looks like this:
render(){
return(
<div>
<a href="http://www.google.com">
<div className="box">
<h2 className="title">Random Title</h2>
<button onClick={this.handleClick}> Like </button>
</div>
</a>
</div>
)
}
handleClick() would look something like this:
handleClick = () => {
if (this.state.liked) {
console.log("disliking")
} else {
console.log("liking")
}
this.setState({ liked: !this.state.liked})
}