Avoid triggering all other event listeners in React

Michael K Snead
Apr 24 · 1 min read
class Clickable extends React.Component {
handleClick = (event, importantStuff) => {
event.stopPropagation()
event.preventDefault()
this.props.doThingsWith(importantStuff)
}
grabClick = (e, importantStuff) => {
if(!e) { return }
e.onclick = (event) => this.handleClick(event, importantStuff)
}
render() {
const importantStuff = true // things in "render" scope can be passed along
return <a href="/nowhere" ref={(e) => this.grabClick(e, importantStuff)} />
}
}
Michael K Snead

Written by

Technology enthusiast, passionate lover of JavaScript, natively fluent speaker of C#.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade