From 55846011243a977fb3ad9eb81b87d5089cc38092 Mon Sep 17 00:00:00 2001 From: Lou Regla Date: Mon, 11 Jan 2021 17:30:22 -0800 Subject: [PATCH] #624 Refactor to move code out of deprecated componentWillRecieveProps in Autowhatever component --- src/Autowhatever.js | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/Autowhatever.js b/src/Autowhatever.js index fe2ee8e7..fd2c247a 100644 --- a/src/Autowhatever.js +++ b/src/Autowhatever.js @@ -95,25 +95,18 @@ export default class Autowhatever extends Component { this.ensureHighlightedItemIsVisible(); } - // eslint-disable-next-line camelcase, react/sort-comp - UNSAFE_componentWillReceiveProps(nextProps) { - if (nextProps.items !== this.props.items) { - this.setSectionsItems(nextProps); - } + componentDidUpdate(prevProps) { + const itemsDidChange = prevProps.items !== this.props.items; - if ( - nextProps.items !== this.props.items || - nextProps.multiSection !== this.props.multiSection - ) { - this.setSectionIterator(nextProps); + if (itemsDidChange) { + this.setSectionsItems(this.props); } - - if (nextProps.theme !== this.props.theme) { - this.setTheme(nextProps); + if (itemsDidChange || prevProps.multiSection !== this.props.multiSection) { + this.setSectionIterator(this.props); + } + if (prevProps.theme !== this.props.theme) { + this.setTheme(this.props); } - } - - componentDidUpdate() { this.ensureHighlightedItemIsVisible(); }