Created
February 4, 2015 02:47
-
-
Save irvinebroque/a4530228bdab51fa3939 to your computer and use it in GitHub Desktop.
React.js Inline Styles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
} | |
}; | |
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> | |
</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