Last active
August 29, 2015 14:24
-
-
Save cheeyeo/464fe0bf75ca28ec9af8 to your computer and use it in GitHub Desktop.
REACTJS
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
// calling setProps is not good practice | |
// instead render the component outside of the react loop | |
React.render( | |
myComponent({ data: someData2 }), | |
document.getElementById('predictionContent') | |
); |
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
// 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); |
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
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 }); |
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
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