Skip to content

Commit

Permalink
Fix React 16.3 deprecation warnings (#223)
Browse files Browse the repository at this point in the history
* Add Sections parameter to the renderHeader and renderContent callbacks.

See #126

* Fix React 16.3 deprecation warnings for componentWillReceiveProps.

Replace componentWillReceiveProps with componentDidUpdate and adjust logic accordingly.

* Check that `activeSection` has changed before updating state.

Fixes infinite loop setState
  • Loading branch information
iRoachie authored Jul 22, 2018
1 parent 5ce76b1 commit 2c135ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
9 changes: 6 additions & 3 deletions Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
}
Expand Down
20 changes: 10 additions & 10 deletions Collapsible.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 2c135ab

Please sign in to comment.