-
-
Save kristoferbaxter/a423a64d0d2a7634daee6eac5188ee60 to your computer and use it in GitHub Desktop.
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
import React from "react"; | |
import { Location } from "@reach/router"; | |
let scrollPositions = {}; | |
class ManageScrollImpl extends React.Component { | |
componentWillUnmount() { | |
scrollPositions[this.props.location.key] = window.scrollY; | |
} | |
componentDidUpdate() { | |
window.scrollTo(0, scrollPositions[this.props.location.key] || 0); | |
} | |
render() { | |
return null; | |
} | |
} | |
export default () => ( | |
<Location> | |
{({ location }) => <ManageScrollImpl location={location} />} | |
</Location> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Answered here.