Last active
March 2, 2019 18:26
-
-
Save andrzejewsky/79bcc1f17d3eedc11124be3a0b587a18 to your computer and use it in GitHub Desktop.
Netflix slider size element hook
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, useRef, useEffect } from 'react' | |
const useSizeElement = () => { | |
const elementRef = useRef(null); | |
const [width, setWidth] = useState(0); | |
useEffect(() => { | |
setWidth(elementRef.current.clientWidth); | |
}, [elementRef.current]); | |
return { width, elementRef }; | |
} | |
export default useSizeElement; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment