Skip to content

Instantly share code, notes, and snippets.

@miklschmidt
Last active August 29, 2015 14:22
Show Gist options
  • Save miklschmidt/dbcca2a083bf505ab7cc to your computer and use it in GitHub Desktop.
Save miklschmidt/dbcca2a083bf505ab7cc to your computer and use it in GitHub Desktop.
Flux and request tracking: part 1
class SomeComponent extends React.Component {
getInitialState() {
return {
requestId: null
}
}
createArticleSuccess() {
// Do stuff on success..
}
createArticleError() {
// Do stuff on error..
}
resetRequestId() {
this.setState({requestId: null});
}
render() {
let requestTracker = null;
if (this.state.requestId !== null) {
requestTracker = <RequestTracker
requestId={this.state.requestId}
success={this.createArticleSuccess}
fail={this.createArticleError}
always={this.resetRequestId} />;
}
return <div className="my-component">
<h1>Hello world</h1>
{requestTracker}
</div>;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment