-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Admin UI: refactored out uses of withRouter
- Loading branch information
Showing
4 changed files
with
140 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@keystonejs/app-admin-ui': patch | ||
--- | ||
|
||
Refactored out uses of the `withRouter` HOC. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import { Component } from 'react'; | ||
import { withRouter } from 'react-router-dom'; | ||
|
||
class ScrollToTop extends Component { | ||
componentDidUpdate(prevProps) { | ||
if (this.props.location !== prevProps.location) { | ||
window.scrollTo(0, 0); | ||
} | ||
} | ||
render() { | ||
return this.props.children; | ||
} | ||
} | ||
|
||
export default withRouter(ScrollToTop); | ||
import { useEffect } from 'react'; | ||
import { useLocation } from 'react-router-dom'; | ||
|
||
const ScrollToTop = ({ children }) => { | ||
const location = useLocation(); | ||
|
||
useEffect(() => { | ||
window.scrollTo(0, 0); | ||
}, [location]); | ||
|
||
return children; | ||
}; | ||
|
||
export default ScrollToTop; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters