React Base Fiddle (JSX)
Starting point for creating JSFiddles with React. This uses React with Addons.
by justindeal
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script src="https://fb.me/react-with-addons-0.14.0.js"></script>
<script src="https://fb.me/react-dom-0.14.0.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
CSS
.container {
border: 1px solid black;
width: 400px;
white-space: nowrap;
overflow: hidden;
}
.wrapper {
position: relative;
display: inline-block;
width: 200px;
}
.hidden {
display: inline-block;
visibility: hidden;
background-color: gray;
}
JavaScript 1.7
var TestMouseEvents = React.createClass({
getInitialState() {
return {
isHovering: false
};
},
onMouseEnter() {
console.log('enter');
this.setState({
isHovering: true
});
},
onMouseLeave() {
console.log('exit');
this.setState({
isHovering: false
});
},
render: function() {
return (
<div className="container">
<span className="wrapper">
<span className="hidden">
Silly hidden thing that extends past the other element.
</span>
</span>
<span className="hover-over-me"
onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}
>Hover over me!
</span>
<div style={{display: this.state.isHovering ? '' : 'none'}}>Hovering!</div>
</div>
)
}
});
ReactDOM.render(
<TestMouseEvents/>,
document.getElementById('container')
);