Skip to content

Instantly share code, notes, and snippets.

@DZuz14
Created March 2, 2020 14:37
Show Gist options
  • Save DZuz14/6f15f3d16470e2f6e7da0f33093393cc to your computer and use it in GitHub Desktop.
Save DZuz14/6f15f3d16470e2f6e7da0f33093393cc to your computer and use it in GitHub Desktop.
Resizing Handling
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