I wrote a React component which renders rating and visualizes it with stars. But I had to use dangerouslySetInnerHTML for that. How could I rewrite component with better code style and without dangerouslySetInnerHTML? Thank you for any help.
export default class BookRating extends React.Component {
renderStars = () => {
let result = '';
for(let i=1; i<=5; i++) {
this.props.rating >= i
? result += '<div class="fa fa-star checked"></div>'
: result += '<div class="fa fa-star"></div>'
}
return result;
}
render () {
return (
<div className="rating" dangerouslySetInnerHTML={{ __html: this.renderStars() }} />
);
}
}