Skip to content

Instantly share code, notes, and snippets.

@irvinebroque
Created February 4, 2015 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irvinebroque/520871ff44042b91b518 to your computer and use it in GitHub Desktop.
Save irvinebroque/520871ff44042b91b518 to your computer and use it in GitHub Desktop.
var React = require('react');
var myComponent = React.createClass({
getInitialState: function() {
return {
hover: false
};
},
render: function() {
var styles = {
container: {
height: 100,
width: '100%'
},
button: {
backgroundColor: 'blue'
},
tooltip: {
position: 'absolute',
backgroundColor: 'black',
color: 'white',
// ...
}
};
if (this.state.hover) {
styles.button.backgroundColor = 'darkBlue';
}
return (
<div style={styles.container}>
<button style={styles.button} onMouseOver={this.onMouseOver} onMouseOut={this.onMouseOut} >Click me</button>
{this.state.hover ? <span style={styles.tooltip}>Really, click me!</span> : null}
</div>
);
},
onMouseOver: function() {
this.setState({hover: true});
},
onMouseOut: function() {
this.setState({hover: false});
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment