components/scroll-manager: use getSnapshotBeforeUpdate

componentWillReceiveProps is deprecated.
This commit is contained in:
Simon Ser 2024-07-02 08:59:43 +02:00
parent 6c324d44a1
commit 331a2f0c4e

View File

@ -14,7 +14,7 @@ export default class ScrollManager extends Component {
return target.scrollTop >= target.scrollHeight - target.offsetHeight; return target.scrollTop >= target.scrollHeight - target.offsetHeight;
} }
saveScrollPosition() { saveScrollPosition(scrollKey) {
let target = this.props.target.current; let target = this.props.target.current;
let sticky = target.querySelectorAll(this.props.stickTo); 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() { restoreScrollPosition() {
@ -64,9 +64,9 @@ export default class ScrollManager extends Component {
this.props.target.current.addEventListener("scroll", this.handleScroll); this.props.target.current.addEventListener("scroll", this.handleScroll);
} }
componentWillReceiveProps(nextProps) { getSnapshotBeforeUpdate(prevProps) {
if (this.props.scrollKey !== nextProps.scrollKey || this.props.children !== nextProps.children) { if (this.props.scrollKey !== prevProps.scrollKey || this.props.children !== prevProps.children) {
this.saveScrollPosition(); this.saveScrollPosition(prevProps.scrollKey);
} }
} }
@ -79,7 +79,7 @@ export default class ScrollManager extends Component {
componentWillUnmount() { componentWillUnmount() {
this.props.target.current.removeEventListener("scroll", this.handleScroll); this.props.target.current.removeEventListener("scroll", this.handleScroll);
this.saveScrollPosition(); this.saveScrollPosition(this.props.scrollKey);
} }
render() { render() {