Last active
November 11, 2017 16:48
-
-
Save greim/853d436c6dea4df6086bf77bb7f9a443 to your computer and use it in GitHub Desktop.
Fetch Logic
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 ProductDetailPage extends React.Component { | |
componentDidMount() { | |
... | |
const hasRealestate = this.props.viewportWidth > 800; | |
const hasData = this.props.relatedProductInfo === undefined; | |
if (hasRealestate && !hasData) { | |
this.props.fetchRelatedProductInfo(this.props.productId); | |
} | |
} | |
render() { | |
const hasRealestate = this.props.viewportWidth > 800; | |
const hasData = this.props.relatedProductInfo !== undefined; | |
return <div> | |
... | |
{ hasRealestate && | |
( hasData | |
? <RelatedProducts products={this.props.relatedProductInfo}/> | |
: <div>Loading...</div> | |
) | |
} | |
</div>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment