Created
June 19, 2015 17:15
-
-
Save colinmegill/aefb2fc6b7da87877483 to your computer and use it in GitHub Desktop.
Basic inline styles with state example for CSSConf
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
<!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