Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(compat): upgrade RangeSlider lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Apr 8, 2019
1 parent 5ff2f51 commit e5a7442
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
15 changes: 9 additions & 6 deletions packages/react-instantsearch-dom/src/widgets/RangeSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ class Range extends React.Component {
state = { currentValues: { min: this.props.min, max: this.props.max } };
componentWillReceiveProps(sliderState) {
// @TODO: Derived State, maybe render
if (sliderState.canRefine) {
componentDidUpdate(prevProps) {
if (
this.props.canRefine &&
(prevProps.currentRefinement.min !== this.props.currentRefinement.min ||
prevProps.currentRefinement.max !== this.props.currentRefinement.max)
) {
this.setState({
currentValues: {
min: sliderState.currentRefinement.min,
max: sliderState.currentRefinement.max
}
min: this.props.currentRefinement.min,
max: this.props.currentRefinement.max,
},
});
}
}
Expand Down
13 changes: 8 additions & 5 deletions stories/3rdPartyIntegrations.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ class Range extends Component {

state = { currentValues: { min: this.props.min, max: this.props.max } };

componentWillReceiveProps(sliderState) {
// @TODO: Derived State, maybe render
if (sliderState.canRefine) {
componentDidUpdate(prevProps) {
if (
this.props.canRefine &&
(prevProps.currentRefinement.min !== this.props.currentRefinement.min ||
prevProps.currentRefinement.max !== this.props.currentRefinement.max)
) {
this.setState({
currentValues: {
min: sliderState.currentRefinement.min,
max: sliderState.currentRefinement.max,
min: this.props.currentRefinement.min,
max: this.props.currentRefinement.max,
},
});
}
Expand Down

0 comments on commit e5a7442

Please sign in to comment.