Skip to content

Commit

Permalink
Fixed an issue that the checked state may be changed unexpectedly whe…
Browse files Browse the repository at this point in the history
…n receiving props that didn't change
  • Loading branch information
cheton committed Oct 27, 2017
1 parent 950f556 commit d8d919d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ToggleSwitch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class ToggleSwitch extends PureComponent {
};

componentWillReceiveProps(nextProps) {
this.setState({ checked: nextProps.checked });
if (this.props.checked !== nextProps.checked) {
this.setState({ checked: nextProps.checked });
}
}
get checked() {
return this.state.checked;
Expand Down

0 comments on commit d8d919d

Please # to comment.