Last active
July 25, 2018 08:22
-
-
Save selbekk/8496377c04d6742b0bf396738d2ebe21 to your computer and use it in GitHub Desktop.
A pretty neat boring ol' 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.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