Skip to content

Instantly share code, notes, and snippets.

@irvinebroque
Created February 4, 2015 02:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irvinebroque/a4530228bdab51fa3939 to your computer and use it in GitHub Desktop.
Save irvinebroque/a4530228bdab51fa3939 to your computer and use it in GitHub Desktop.
React.js Inline Styles
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