1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Scroll to the hash only if there's one after an error. (#2224)

This commit is contained in:
Arunoda Susiripala 2017-06-10 03:15:37 +05:30 committed by Tim Neutkens
parent ad4ec554ca
commit 4726c4352e

View file

@ -44,13 +44,15 @@ class Container extends Component {
scrollToHash () {
const { hash } = this.props
if (!hash) return
const el = document.getElementById(hash)
if (el) {
if (!el) return
// If we call scrollIntoView() in here without a setTimeout
// it won't scroll properly.
setTimeout(() => el.scrollIntoView(), 0)
}
}
shouldComponentUpdate (nextProps) {
// need this check not to rerender component which has already thrown an error