mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-14 19:25:26 -05:00
components/scroll-manager: use getSnapshotBeforeUpdate
componentWillReceiveProps is deprecated.
This commit is contained in:
parent
6c324d44a1
commit
331a2f0c4e
1 changed files with 6 additions and 6 deletions
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue