Skip to content

Commit

Permalink
Refactor #36
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Jul 3, 2017
1 parent 489fb49 commit c2f025a
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/components/rating/Rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ export class Rating extends Component {
rate(event, i){
if(!this.props.readonly&&!this.props.disabled) {
var _value = (i + 1);
this.props.onChange({
originalEvent: event,
value: _value
});
this.setState({value: _value});

if(_value !== this.state.value) {
this.props.onChange({
originalEvent: event,
value: _value
});
this.setState({value: _value});
}
}
event.preventDefault();
}
Expand All @@ -56,11 +59,12 @@ export class Rating extends Component {
}
}

componentWillReceiveProps(nextProps) {
var newValue = nextProps.value;
if (newValue !== this.state.value) {
this.setState({value: newValue});
}
shouldComponentUpdate(nextProps, nextState) {
if(nextState.value === this.state.value) {
return false;
}

return true;
}

render() {
Expand Down

0 comments on commit c2f025a

Please sign in to comment.