Last active
October 31, 2019 10:37
-
-
Save jflessau/5d6b76f710c0203048aaadd761877fe8 to your computer and use it in GitHub Desktop.
React: Hook for scrolling a page all the way up.
This file contains hidden or 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 { 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