diff --git a/Accordion.js b/Accordion.js index 9f5a140..7e1bf43 100644 --- a/Accordion.js +++ b/Accordion.js @@ -51,10 +51,13 @@ export default class Accordion extends Component { }; } - componentWillReceiveProps(nextProps) { - if (nextProps.activeSection !== undefined) { + componentDidUpdate(prevProps, prevState) { + if ( + this.props.activeSection !== undefined && + this.props.activeSection !== prevProps.activeSection + ) { this.setState({ - activeSection: nextProps.activeSection, + activeSection: this.props.activeSection, }); } } diff --git a/Collapsible.js b/Collapsible.js index bb1e939..ede6aad 100644 --- a/Collapsible.js +++ b/Collapsible.js @@ -37,24 +37,24 @@ export default class Collapsible extends Component { }; } - componentWillReceiveProps(nextProps) { - if (!nextProps.collapsed && !this.props.collapsed) { + componentDidUpdate(prevProps, prevState) { + if (prevProps.collapsed !== this.props.collapsed) { this.setState({ measured: false }, () => - this._componentWillReceiveProps(nextProps) + this._componentDidUpdate(prevProps) ); } else { - this._componentWillReceiveProps(nextProps); + this._componentDidUpdate(prevProps); } } - _componentWillReceiveProps(nextProps) { - if (nextProps.collapsed !== this.props.collapsed) { - this._toggleCollapsed(nextProps.collapsed); + _componentDidUpdate(prevProps) { + if (prevProps.collapsed !== this.props.collapsed) { + this._toggleCollapsed(this.props.collapsed); } else if ( - nextProps.collapsed && - nextProps.collapsedHeight !== this.props.collapsedHeight + this.props.collapsed && + prevProps.collapsedHeight !== this.props.collapsedHeight ) { - this.state.height.setValue(nextProps.collapsedHeight); + this.state.height.setValue(this.props.collapsedHeight); } }