Skip to content

Instantly share code, notes, and snippets.

@cheeyeo
Last active August 29, 2015 14:24
Show Gist options
  • Save cheeyeo/464fe0bf75ca28ec9af8 to your computer and use it in GitHub Desktop.
Save cheeyeo/464fe0bf75ca28ec9af8 to your computer and use it in GitHub Desktop.
REACTJS
// calling setProps is not good practice
// instead render the component outside of the react loop
React.render(
myComponent({ data: someData2 }),
document.getElementById('predictionContent')
);
// simple example of a data model
var Data = { name: 'world' };
var World = React.createClass({
render: function() {
return <strong>{this.props.data.name}</strong>;
}
});
var Hello = React.createClass({
clickHandler: function() {
this.setProps({
data: { name: 'earth' }
});
},
render: function() {
return (
<div>
Hello <World data={this.props.data} />
<button onClick={this.clickHandler}>Click me</button>
</div>
);
}
});
React.render(<Hello data={Data} />, document.body);
var MyComponent = React.createClass({
render: function () {
return React.DOM.div(null, this.props.data);
}
});
var myComponent = React.renderComponent(
new MyComponent({ data: someData }),
document.getElementById('predictionContent')
);
myComponent.setProps({ data: someData2 });
var myElement = React.createElement(
MyElement,
{hello: "world"}
);
React.render(myElement, document.body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment