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/af31679e0f0093da9eb0e2ca54dbcacc to your computer and use it in GitHub Desktop.
Save selbekk/af31679e0f0093da9eb0e2ca54dbcacc to your computer and use it in GitHub Desktop.
A slightly less boring ol' API backed page
class SomePage extends React.Component {
async componentDidMount() {
const { apiState } = this.props;
apiState.next();
try {
const res = await fetch('/api/some-data');
const data = await res.json();
apiState.next(true);
} catch (e) {
apiState.next(false);
}
}
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