Download spectrum/src/hooks/useAppScroller.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 733 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/src/hooks/useAppScroller.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/src/hooks/useAppScroller.js
-
curl -L -o useAppScroller.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/src/hooks/useAppScroller.js
733 Bytes
| // @flow | |
| import { useState, useEffect } from 'react'; | |
| export const useAppScroller = () => { | |
| const [ref, setRef] = useState(null); | |
| useEffect(() => { | |
| if (!ref) setRef(document.getElementById('main')); | |
| }); | |
| const scrollToTop = () => { | |
| const elem = ref || document.getElementById('main'); | |
| if (elem) return (elem.scrollTop = 0); | |
| }; | |
| const scrollToBottom = () => { | |
| const elem = ref || document.getElementById('main'); | |
| if (elem) return (elem.scrollTop = elem.scrollHeight - elem.clientHeight); | |
| }; | |
| const scrollTo = (pos: number) => { | |
| const elem = ref || document.getElementById('main'); | |
| if (elem) return (elem.scrollTop = pos); | |
| }; | |
| return { scrollToTop, scrollTo, scrollToBottom, ref }; | |
| }; | |