Skip to content

Instantly share code, notes, and snippets.

@colinmegill
Created June 19, 2015 17:15
Show Gist options
  • Save colinmegill/aefb2fc6b7da87877483 to your computer and use it in GitHub Desktop.
Save colinmegill/aefb2fc6b7da87877483 to your computer and use it in GitHub Desktop.
Basic inline styles with state example for CSSConf
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
</style>
<script src="http://fb.me/react-0.12.2.js"></script>
<script src="http://fb.me/JSXTransformer-0.12.2.js"></script>
</head>
<body>
<script type="text/jsx">
var Recipe = React.createClass({
getInitialState : function() {
return {
color : "darkred",
fontSize : 14
};
},
handleColorChange: function (e) {
this.setState({
color: e.target.value
})
},
handleSizeChange: function (e) {
this.setState({
fontSize: e.target.value
})
},
render : function() {
return (
<div>
<input onChange={this.handleColorChange}/>
<input onChange={this.handleSizeChange} />
<p
style={{
color: this.state.color,
fontSize: this.state.fontSize
}}
>
This paragraph is {this.state.color} and {this.state.fontSize} px
</p>
</div>
)
}
});
React.renderComponent(
<Recipe />,
document.body
);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment