import React, { Component } from 'react'; import PropTypes from 'prop-types'; import _ from 'lodash'; import { styles } from './styles'; class Rating extends Component { constructor(props) { super(props); this.clickStar = this.clickStar.bind(this); } shouldComponentUpdate() { // when component re render lost checked item return false; } clickStar(e) { this.props.onRate(e); } renderStars(num) { return (
{ _.range(num) .map(i => [( this.clickStar(i + 1)} />), (), ]).reverse() }
); } render() { const { total, } = this.props; return (
{ this.renderStars(total) }
); } } export default Rating;