我使用Array.fill()来打印星号,但代码只显示1个星号…]
import React from 'react'
function Rating(props) {
const {rating, numReviews} = props;
return (
<div className="product_rating">
{Array(rating)
.fill()
.map((_, _i) => (
<p>🌟</p>
))
}
</div>
)
}
export default Rating;
UPD:如果评级是字符串使用parseInt
{Array(parseInt(rating))
.fill()
.map((_, _i) => (
<p>🌟</p>
))}