diff --git a/components/scroll-manager.js b/components/scroll-manager.js index 2977e3f..4106948 100644 --- a/components/scroll-manager.js +++ b/components/scroll-manager.js @@ -14,7 +14,7 @@ export default class ScrollManager extends Component { return target.scrollTop >= target.scrollHeight - target.offsetHeight; } - saveScrollPosition() { + saveScrollPosition(scrollKey) { let target = this.props.target.current; let sticky = target.querySelectorAll(this.props.stickTo); @@ -29,7 +29,7 @@ export default class ScrollManager extends Component { } } - store.set(this.props.scrollKey, stickToKey); + store.set(scrollKey, stickToKey); } restoreScrollPosition() { @@ -64,9 +64,9 @@ export default class ScrollManager extends Component { this.props.target.current.addEventListener("scroll", this.handleScroll); } - componentWillReceiveProps(nextProps) { - if (this.props.scrollKey !== nextProps.scrollKey || this.props.children !== nextProps.children) { - this.saveScrollPosition(); + getSnapshotBeforeUpdate(prevProps) { + if (this.props.scrollKey !== prevProps.scrollKey || this.props.children !== prevProps.children) { + this.saveScrollPosition(prevProps.scrollKey); } } @@ -79,7 +79,7 @@ export default class ScrollManager extends Component { componentWillUnmount() { this.props.target.current.removeEventListener("scroll", this.handleScroll); - this.saveScrollPosition(); + this.saveScrollPosition(this.props.scrollKey); } render() {