Skip to content

Instantly share code, notes, and snippets.

@andrzejewsky
Last active March 2, 2019 18:26
Show Gist options
  • Save andrzejewsky/79bcc1f17d3eedc11124be3a0b587a18 to your computer and use it in GitHub Desktop.
Save andrzejewsky/79bcc1f17d3eedc11124be3a0b587a18 to your computer and use it in GitHub Desktop.
Netflix slider size element hook
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