From 2b340d3d71137e7933db339470785950552ea5e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Mon, 8 Apr 2019 16:45:14 +0200 Subject: [PATCH] fix(compat): upgrade SearchBox lifecycle --- .../src/components/SearchBox.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/react-instantsearch-dom/src/components/SearchBox.js b/packages/react-instantsearch-dom/src/components/SearchBox.js index 08f66f7baf..a3fb0ee658 100644 --- a/packages/react-instantsearch-dom/src/components/SearchBox.js +++ b/packages/react-instantsearch-dom/src/components/SearchBox.js @@ -115,19 +115,13 @@ class SearchBox extends Component { document.removeEventListener('keydown', this.onKeyDown); } - componentWillReceiveProps(nextProps) { - // @TODO: should component maybe be controlled, otherwise Derived - - // Reset query when the searchParameters query has changed. - // This is kind of an anti-pattern (props in state), but it works here - // since we know for sure that searchParameters having changed means a - // new search has been triggered. + componentDidUpdate(prevProps) { if ( - !nextProps.searchAsYouType && - nextProps.currentRefinement !== this.props.currentRefinement + !prevProps.searchAsYouType && + prevProps.currentRefinement !== this.props.currentRefinement ) { this.setState({ - query: nextProps.currentRefinement, + query: this.props.currentRefinement, }); } }