useIsPresent in Child Component
useIsPresent must be called from child of AnimatePresence, not parent.
Incorrect (hook in parent):
function Parent() {
const isPresent = useIsPresent();
return (
<AnimatePresence>
{show && <Child />}
</AnimatePresence>
);
}Correct (hook in child):
function Child() {
const isPresent = useIsPresent();
return <motion.div data-exiting={!isPresent} />;
}