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 React Router example lifecycles (#2307)
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour authored and Haroenv committed Jun 27, 2019
1 parent fff5aa6 commit ab828b0
Show file tree
Hide file tree
Showing 2 changed files with 1,839 additions and 2,691 deletions.
21 changes: 10 additions & 11 deletions examples/react-router/src/App.js
Expand Up @@ -29,29 +29,26 @@ const searchStateToUrl = (props, searchState) =>
const urlToSearchState = location => qs.parse(location.search.slice(1));

class App extends Component {
constructor(props) {
super(props);

this.state = {
searchState: urlToSearchState(props.location),
};
}
state = {
searchState: urlToSearchState(this.props.location),
};

componentWillReceiveProps(props) {
// @TODO: derived state
if (props.location !== this.props.location) {
this.setState({ searchState: urlToSearchState(props.location) });
componentDidUpdate(prevProps) {
if (prevProps.location !== this.props.location) {
this.setState({ searchState: urlToSearchState(this.props.location) });
}
}

onSearchStateChange = searchState => {
clearTimeout(this.debouncedSetState);

this.debouncedSetState = setTimeout(() => {
this.props.history.push(
searchStateToUrl(this.props, searchState),
searchState
);
}, updateAfter);

this.setState({ searchState });
};

Expand All @@ -77,6 +74,7 @@ class App extends Component {
<SearchBox />
<PoweredBy />
</div>

<div style={{ display: 'flex' }}>
<div style={{ padding: '0px 20px' }}>
<p>Hierarchical Menu</p>
Expand All @@ -95,6 +93,7 @@ class App extends Component {
<p>Range Ratings</p>
<RatingMenu attribute="rating" max={6} />
</div>

<div style={{ display: 'flex', flexDirection: 'column', flex: 1 }}>
<div style={{ display: 'flex', justifyContent: 'space-around' }}>
<ClearRefinements />
Expand Down

0 comments on commit ab828b0

Please sign in to comment.