Presence
Manages element mounting and unmounting with animation support.
Installation
pnpm dlx shadcn@latest add @diceui/presenceUsage
import { Presence } from "@/components/presence"
export default function AnimatedModal({ isOpen }: { isOpen: boolean }) {
return (
<Presence present={isOpen}>
<div className="animate-fade-in">
Modal content
</div>
</Presence>
)
}With Render Function
Access the present state for exit animations:
import { Presence } from "@/components/presence"
export default function FadeModal({ isOpen }: { isOpen: boolean }) {
return (
<Presence present={isOpen}>
{({ present }) => (
<div
className={cn(
"transition-opacity duration-300",
present ? "opacity-100" : "opacity-0"
)}
>
Modal content
</div>
)}
</Presence>
)
}API Reference
Presence
Manages the mounting and unmounting of components with animation support.
Prop
Type
How it Works
The Presence component ensures that content remains mounted in the DOM during exit animations:
- When
presentbecomestrue, the element is immediately mounted - When
presentbecomesfalse, the element stays mounted to allow exit animations - The render function receives the current
presentstate for conditional styling
This is essential for CSS animations and transitions that need the element to remain in the DOM while animating out.
Credits
Inspired by Radix UI's Presence primitive.