Skip to content

Instantly share code, notes, and snippets.

@DZuz14
Created March 2, 2020 14:20
Show Gist options
  • Save DZuz14/7aaa3edd32e72f61a11d4f8378d06f0a to your computer and use it in GitHub Desktop.
Save DZuz14/7aaa3edd32e72f61a11d4f8378d06f0a to your computer and use it in GitHub Desktop.
Transition Ref and Listener
const autoPlayRef = useRef()
const transitionRef = useRef()
useEffect(() => {
autoPlayRef.current = nextSlide
transitionRef.current = smoothTransition
})
useEffect(() => {
const play = () => {
autoPlayRef.current()
}
const smooth = () => {
transitionRef.current()
}
const interval = setInterval(play, props.autoPlay * 1000)
const transitionEnd = window.addEventListener('transitionend', smooth)
return () => {
clearInterval(interval)
window.removeEventListener('transitionend', transitionEnd)
}
}, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment