Skip to content

Instantly share code, notes, and snippets.

@Enome
Last active August 29, 2015 14:01
Show Gist options
  • Save Enome/5083925d40bebc9834bb to your computer and use it in GitHub Desktop.
Save Enome/5083925d40bebc9834bb to your computer and use it in GitHub Desktop.
/** @jsx React.DOM */
var data = arrayWithEvents;
var ErrorComponent = React.createClass({
/* LOGIC */
_update: function () {
this.setState({ errors: data.errors() })
},
/* LIFECYCLE EVENTS */
componentDidMount: function () {
data.errors.onChange(this._update);
},
componentWillUnmount: function () {
data.errors.removeListener(this._update);
};
getInitialState: function () {
return {
errors: data.errors()
};
},
/* RENDER */
render: function () {
return ();
},
});
var SomeComponent = React.createClass({
/* LOGIC */
raiseError: function () {
data.errors.push({ type: 'warning', msg: 'Something went wrong with this '});
},
/* RENDER */
render: function () {
return (
<div onClick={this.raiseError}>Error</div>
);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment