mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
Create app namespace for all absolute requires of app modules. Move all packages under packages yarn workspace
This commit is contained in:
36
packages/app/components/ui/scroll/ScrollIntoView.tsx
Normal file
36
packages/app/components/ui/scroll/ScrollIntoView.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import { RouteComponentProps } from 'react-router-dom';
|
||||
import React from 'react';
|
||||
import { withRouter } from 'react-router-dom';
|
||||
import { restoreScroll } from './scroll';
|
||||
|
||||
class ScrollIntoView extends React.PureComponent<
|
||||
RouteComponentProps & {
|
||||
top?: boolean; // do not touch any DOM and simply scroll to top on location change
|
||||
}
|
||||
> {
|
||||
componentDidMount() {
|
||||
this.onPageUpdate();
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (this.props.location !== prevProps.location) {
|
||||
this.onPageUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
onPageUpdate() {
|
||||
if (this.props.top) {
|
||||
restoreScroll();
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.props.top) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <span ref={el => el && restoreScroll(el)} />;
|
||||
}
|
||||
}
|
||||
|
||||
export default withRouter(ScrollIntoView);
|
Reference in New Issue
Block a user