diff --git a/src/components/ProductDetail.js b/src/components/ProductDetail.js index 885919a..f6b7352 100644 --- a/src/components/ProductDetail.js +++ b/src/components/ProductDetail.js @@ -1,4 +1,5 @@ import React from "react"; +import Reviews from "./Reviews"; function ProductDetail(props) { const {name,description,rating,imgUrl} = props.product; @@ -6,7 +7,7 @@ function ProductDetail(props) { for (let i = 0; i < rating; i++) { stars.push(); } - + //console.log(props.product); return (
@@ -18,7 +19,7 @@ function ProductDetail(props) {

-

15 reviews

+

{stars}

diff --git a/src/components/Reviews.js b/src/components/Reviews.js new file mode 100644 index 0000000..937348a --- /dev/null +++ b/src/components/Reviews.js @@ -0,0 +1,49 @@ +import React from "react"; + +class Reviews extends React.Component { + constructor() { + super(); + this.state = { + visible: false + }; + } + render() { + const reviews = this.props.product.reviews; + console.log(reviews.length); + + let reviewName = ""; + if (reviews.length == 1 ){ + reviewName = "Review"; + } + else{ + reviewName = "Reviews"; + } + + let reviewDivs = ""; + if (this.state.visible){ + reviewDivs = reviews.map(function (review,i){ + return
{review.description}
+ }); + + } + else{ + reviewDivs = ""; + } + + return ( +
+ + {reviewDivs} +
+ ); + } +} +export default Reviews; \ No newline at end of file