Last active
July 25, 2018 08:22
-
-
Save selbekk/af31679e0f0093da9eb0e2ca54dbcacc to your computer and use it in GitHub Desktop.
A slightly less boring ol' API backed page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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