Skip to content

Instantly share code, notes, and snippets.

@greim
Last active November 11, 2017 16:48
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 greim/853d436c6dea4df6086bf77bb7f9a443 to your computer and use it in GitHub Desktop.
Save greim/853d436c6dea4df6086bf77bb7f9a443 to your computer and use it in GitHub Desktop.
Fetch Logic
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