Skip to content

Instantly share code, notes, and snippets.

@selbekk
Last active July 25, 2018 08:22
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 selbekk/8496377c04d6742b0bf396738d2ebe21 to your computer and use it in GitHub Desktop.
Save selbekk/8496377c04d6742b0bf396738d2ebe21 to your computer and use it in GitHub Desktop.
A pretty neat boring ol' page!
class SomePage extends React.Component {
async componentDidMount() {
const { apiState } = this.props;
apiState.pending();
try {
const res = await fetch('/api/some-data');
const data = await res.json();
apiState.success();
} catch (e) {
apiState.error();
}
}
render() {
// Renders the appropriate thing based on props!
}
}
const SomeBetterPage = withApiState(SomePage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment