6.1 Building a Star Rating Component: fill functions required by StarRating component
parent
d38c22ac87
commit
09b754eddc
|
@ -14,7 +14,7 @@ export default function Menu({ recipes }) {
|
|||
))}
|
||||
</div>
|
||||
<div>
|
||||
<StarRating />
|
||||
<StarRating totalStars={10}/>
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import React from "react";
|
||||
import { FaStar } from "react-icons/fa";
|
||||
|
||||
export default function StarRating() {
|
||||
return [
|
||||
<FaStar color="red" />,
|
||||
<FaStar color="red" />,
|
||||
<FaStar color="red" />,
|
||||
<FaStar color="grey" />,
|
||||
<FaStar color="grey" />
|
||||
];
|
||||
}
|
||||
export default function StarRating({ totalStars = 5 }) {
|
||||
return createArray(totalStars).map((n, i) => <Star key={i} />);
|
||||
}
|
||||
|
||||
const Star = ({ selected = false }) => (
|
||||
<FaStar color={selected ? "red" : "grey"} />
|
||||
)
|
||||
|
||||
const createArray = length => [...Array(length)];
|
Loading…
Reference in New Issue