Skip to content

Commit

Permalink
Moving to support React async mode: remove unsafe componentWillReceiv…
Browse files Browse the repository at this point in the history
…eProps (#124)
  • Loading branch information
aakula-edmunds authored May 5, 2020
1 parent 1cc9a1a commit 6e2fe75
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/Sticky.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ class Sticky extends Component {
}

getTopPosition (top) {
// TODO, topTarget is for current layout, may remove
// a top argument can be provided to override reading from the props
top = top || this.props.top || this.props.topTarget || 0;
top = top || this.props.top || 0;
if (typeof top === 'string') {
if (!this.topTarget) {
this.topTarget = doc.querySelector(top);
Expand Down Expand Up @@ -282,26 +281,29 @@ class Sticky extends Component {
this.delta = delta;
}

componentWillReceiveProps (nextProps) {
this.updateInitialDimension(nextProps);
this.update();
}

componentDidUpdate(prevProps, prevState) {
if (prevState.status !== this.state.status && this.props.onStateChange) {
this.props.onStateChange({status: this.state.status});
}
// if the props for enabling are toggled, then trigger the update or reset depending on the current props
if (prevProps.enabled !== this.props.enabled) {
if (this.props.enabled) {
this.setState({activated: true}, () => {
this.updateInitialDimension();
this.update();
});
} else {
this.setState({activated: false}, () => {
this.reset();
});
const arePropsChanged = !shallowEqual(this.props, prevProps);
if (arePropsChanged) {
// if the props for enabling are toggled, then trigger the update or reset depending on the current props
if (prevProps.enabled !== this.props.enabled) {
if (this.props.enabled) {
this.setState({ activated: true }, () => {
this.updateInitialDimension();
this.update();
});
} else {
this.setState({ activated: false }, () => {
this.reset();
});
}
}
// if the top or bottomBoundary props were changed, then trigger the update
else if (prevProps.top !== this.props.top || prevProps.bottomBoundary !== this.props.bottomBoundary) {
this.updateInitialDimension();
this.update();
}
}
}
Expand Down

0 comments on commit 6e2fe75

Please sign in to comment.