Skip to content

Instantly share code, notes, and snippets.

@pedroparra
Created August 13, 2015 19:03
Show Gist options
  • Select an option

  • Save pedroparra/447ceee8d35e1d91a6dc to your computer and use it in GitHub Desktop.

Select an option

Save pedroparra/447ceee8d35e1d91a6dc to your computer and use it in GitHub Desktop.
React Js componentWillReceiveProps
// Ecmascript 5
var MyComponent = React.createClass({
componentWillReceiveProps: function(next_props){
this.setState({ loading: true });
},
render: function() {
className = this.state.loading ? 'loading' : 'loaded';
return(<div className={className}>Soy un component</div>)
}
});
// Ecmascript 6
class MyComponent extends React.Component {
componentWillReceiveProps(next_props) {
this.setState({ loading: true });
}
render(){
className = this.state.loading ? 'loading' : 'loaded';
return(<div className={className}>Soy un component</div>)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment