Skip to content

Instantly share code, notes, and snippets.

@susimsek
Last active August 27, 2022 10:38
Show Gist options
  • Save susimsek/a0a64d624bc72807f91f565b116fcf64 to your computer and use it in GitHub Desktop.
Save susimsek/a0a64d624bc72807f91f565b116fcf64 to your computer and use it in GitHub Desktop.
Graphql Product Overview Page
const ProductOverview = () => {
const { id } = useParams();
const { loading, data, error } = useProductAndReviewsQuery({
variables: {
id
},
})
if (loading) {
return <div className="d-flex justify-content-center">
<Spinner animation="border" role="status">
<span className="visually-hidden">Loading...</span>
</Spinner>
</div>
}
if (error) {
return <Container>Error...</Container>
}
return (
<Container>
<Row>
<Card>
<Card.Header className="text-center text-primary">Reviews</Card.Header>
<ListGroup variant="flush">
{data.product.reviews.length === 0 && <ListGroup.Item>There are no reviews</ListGroup.Item>}
{data.product.reviews.map(review => (
<ListGroup.Item key={review.id}>
<>
{review.text}
<StarRating rating={review.starRating}/>
</>
</ListGroup.Item>
))}
</ListGroup>
</Card>
</Row>
</Container>
)
}
export default ProductOverview;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment