usePresence
Returns [isPresent, safeToRemove] for a child inside
<AnimatePresence>. Call safeToRemove after your own exit work
finishes to tell the parent it can unmount the child.
import { AnimatePresence, usePresence } from 'motion-solidjs'
import { createEffect } from 'solid-js'
function Card(props: { ref: (el: HTMLDivElement) => void }) {
const [isPresent, safeToRemove] = usePresence()
createEffect(() => {
if (!isPresent()) {
// run your exit animation here, then notify the parent to unmount
runExitAnimation().then(safeToRemove)
}
})
return <div ref={props.ref}>{/* ... */}</div>
}
isPresent is a reactive accessor, so call it like a function. safeToRemove is a no-op until
the parent <AnimatePresence> has flagged the child for removal.
Hello
Related: useIsPresent (boolean-only), usePresenceData
(read custom data passed via <AnimatePresence custom={...}>).