2020-08-06 04:04:02 +02:00
|
|
|
import React from 'react';
|
2020-09-27 09:51:29 +02:00
|
|
|
import classNames from 'classnames';
|
2020-08-06 04:04:02 +02:00
|
|
|
import styles from './Page.module.css';
|
|
|
|
|
2021-07-25 08:42:13 +02:00
|
|
|
export default class Page extends React.Component {
|
|
|
|
getSnapshotBeforeUpdate() {
|
|
|
|
if (window.pageXOffset === 0 && window.pageYOffset === 0) return null;
|
|
|
|
|
|
|
|
// Return the scrolled position as the snapshot value
|
|
|
|
return { x: window.pageXOffset, y: window.pageYOffset };
|
|
|
|
}
|
|
|
|
|
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
|
componentDidUpdate(prevProps, prevState, snapshot) {
|
|
|
|
if (snapshot !== null) {
|
|
|
|
// Restore the scrolled position after re-rendering
|
|
|
|
window.scrollTo(snapshot.x, snapshot.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* eslint-enable no-unused-vars */
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { className, children } = this.props;
|
|
|
|
return <div className={classNames(styles.page, className)}>{children}</div>;
|
|
|
|
}
|
2020-08-06 04:04:02 +02:00
|
|
|
}
|