Created
March 2, 2020 14:20
-
-
Save DZuz14/7aaa3edd32e72f61a11d4f8378d06f0a to your computer and use it in GitHub Desktop.
Transition Ref and Listener
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() | |
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