Skip to content

Instantly share code, notes, and snippets.

@jflessau
Last active October 31, 2019 10:37
Show Gist options
  • Select an option

  • Save jflessau/5d6b76f710c0203048aaadd761877fe8 to your computer and use it in GitHub Desktop.

Select an option

Save jflessau/5d6b76f710c0203048aaadd761877fe8 to your computer and use it in GitHub Desktop.
React: Hook for scrolling a page all the way up.
import { useState, useEffect } from 'react'
export default function useScrollUp() {
const [init, setInit] = useState(true)
useEffect(() => {
if (init) {
window.scrollTo(0, 0)
setInit(false)
}
}, [init, setInit])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment