Skip to content

Instantly share code, notes, and snippets.

@carlosdiaz
Created September 19, 2015 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosdiaz/b0483b08b64230a1d1f8 to your computer and use it in GitHub Desktop.
Save carlosdiaz/b0483b08b64230a1d1f8 to your computer and use it in GitHub Desktop.
var Hello = React.createClass({
getInitialState : function(){
return { dato1 : 'Marcos', dato2 : 1234};
},
render: function() {
setTimeout(function(){ this.setState( { dato1 : 'Carlos'}); }.bind(this),5000);
return <div>Hello {this.state.dato1}</div>;
}
});
React.render(<Hello name="World" />, document.getElementById('container'));
React.render(<Hello name="World" />, document.getElementById('container1'));
//Second example
var Hello = React.createClass({
getInitialState : function(){
return { dato1 : 'Marcos', dato2 : 1234};
},
getDefaultProps : function() {
//se ejecuta solamente una vez
return {prop1: 'que tal', prop2: ''}
},
render: function() {
//setTimeout(function(){ this.setState( { dato1 : 'Carlos'}); }.bind(this),5000);
return <div>Hello {this.props.prop1}</div>;
}
});
React.render(<Hello prop1="Hola!!" />, document.getElementById('container'));
React.render(<Hello name="World" />, document.getElementById('container1'));
//Third example
var Hello = React.createClass({
getInitialState : function(){
return { dato1 : 'Marcos', dato2 : 1234};
},
getDefaultProps : function() {
//se ejecuta solamente una vez
return {prop1: 'que tal', prop2: ''}
},
render: function() {
//setTimeout(function(){ this.setState( { dato1 : 'Carlos'}); }.bind(this),5000);
return <div>Hello {this.props.prop1}</div>;
}
});
var unNombre = "Carlos Diaz"
React.render(<Hello prop1={unNombre} />, document.getElementById('container'));
React.render(<Hello name="World" />, document.getElementById('container1'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment