Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function useTransitionState(ref) {
let [pending, setPending] = useState(false);
useLayoutEffect(() => {
let target = ref.current;
let handler = {
handleEvent(event) {
setPending(event.type === 'transitionstart');
}
}
target.addEventListener('transitionstart', handler);
target.addEventListener('transitionend', handler);
return () => {
target.removeEventListener('transitionstart', handler);
target.removeEventListener('transitionend', handler);
}
}, []);
return pending;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment