Skip to content

Instantly share code, notes, and snippets.

@heyjohnmurray
Created November 19, 2015 07:18
Show Gist options
  • Save heyjohnmurray/41a77c7e1a39b3d1da70 to your computer and use it in GitHub Desktop.
Save heyjohnmurray/41a77c7e1a39b3d1da70 to your computer and use it in GitHub Desktop.
// You can attach elment attributes to your app and read them in your rendered UI
React.render(<App text="this is a text value. wow!" />, document.body);
// 'text' in this example can now be passed from your app logic to your rendered UI view.
// basic properties instance
var App = React.createClass({
render: function() {
var text = this.props.text;
return (
<h1>{text}</h1>
);
}
});
// passing properties through an object
var App = React.createClass({
propTypes: {
text: React.PropTypes.string // requiring this value to be a string. if not, it casues an error
// text: React.PropTypes.string.isRequired // adding .isRequired does just that and could be good for validation
},
render: function() {
var text = this.props.text;
return (
<h1>{text}</h1>
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment