React Base Fiddle (JSX)
Starting point for creating JSFiddles with React.
HTML
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
Babel + JSX
class Hello extends React.Component {
constructor(props){
super(props);
this.clickCount = 0;
this.singleClickTimer = '';
}
singleClick = () => {
alert('only fire click')
}
handleDoubleClick = () => {
alert('only fire double click')
}
handleClicks(){
this.clickCount++;
if (this.clickCount === 1) {
this.singleClickTimer = setTimeout(function() {
this.clickCount = 0;
this.singleClick();
}.bind(this), 300);
} else if (this.clickCount === 2) {
clearTimeout(this.singleClickTimer);
this.clickCount = 0;
this.handleDoubleClick();
}
}
render() {
return <div>Hello {this.props.name}
<span onClick={() => this.handleClicks()}> clicks</span>
</div>;
}
}
ReactDOM.render(
<Hello name="World" />,
document.getElementById('container')
);