Created
March 2, 2020 14:37
-
-
Save DZuz14/6f15f3d16470e2f6e7da0f33093393cc to your computer and use it in GitHub Desktop.
Resizing Handling
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
const autoPlayRef = useRef() | |
const transitionRef = useRef() | |
const resizeRef = useRef() | |
useEffect(() => { | |
autoPlayRef.current = nextSlide | |
transitionRef.current = smoothTransition | |
resizeRef.current = handleResize | |
}) | |
useEffect(() => { | |
const play = () => { | |
autoPlayRef.current() | |
} | |
const smooth = () => { | |
transitionRef.current() | |
} | |
const resize = () => { | |
resizeRef.current() | |
} | |
const interval = setInterval(play, props.autoPlay * 1000) | |
const transitionEnd = window.addEventListener('transitionend', smooth) | |
const onResize = window.addEventListener('resize', resize) | |
return () => { | |
clearInterval(interval) | |
window.removeEventListener('transitionend', transitionEnd) | |
window.removeEventListener('resize', onResize) | |
} | |
}, []) | |
const handleResize = () => { | |
setState({ ...state, translate: getWidth(), transition: 0 }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment