Created
May 27, 2018 10:46
-
-
Save allenevans/e1f9bd77683ea58db33862c5a438ccff to your computer and use it in GitHub Desktop.
Example of how to render the result of a resolved promise in react
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
import PropTypes from 'prop-types'; | |
import React, { Component, Fragment } from 'react'; | |
class AsyncFragment extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
value: null, | |
}; | |
Promise.resolve(props.value) | |
.then((value) => { | |
this.setState({ value }); | |
}); | |
} | |
render() { | |
return <Fragment>{this.state.value}</Fragment>; | |
} | |
} | |
AsyncFragment.propTypes = { | |
value: PropTypes.object, | |
}; | |
export default AsyncFragment; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment