UNPKG

motion

Version:

The Motion library for the web

24 lines (21 loc) 862 B
import { usePresence } from 'framer-motion'; import { useEffect } from 'react'; import { resolvePose } from '../utils/poses.es.js'; import { updateTargetAndOptions } from '../utils/update-target.es.js'; function useExit(target, options, { exit, poses }, { exit: inheritedExit }) { const [isPresent, onExitComplete] = usePresence(); /** * In case we don't have an exit animation defined we still need to * call onExitComplete if it exits so AnimatePresence knows it * can remove this component. */ useEffect(() => { if (!exit) onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete(); }, [isPresent]); if (exit && !isPresent) { updateTargetAndOptions(target, options, resolvePose(exit, inheritedExit, poses)); return onExitComplete; } } export { useExit };