Skip to content

Presence

Overview

Presence controls when elements are added to and removed from the DOM, enabling CSS-driven enter and exit animations. Instead of immediately removing an element, it transitions through an exiting state allowing animations to complete.

Usage

import { createPresence } from "@paramanu/utilities-js"
const presence = createPresence(element, {
duration: 300,
onExited: () => element.remove(),
})
presence.setPresent(true) // entering -> entered
presence.setPresent(false) // exiting -> exited

Guidelines

  • Match the duration prop to your CSS transition/animation duration
  • Use usePresence hook for custom animation logic
  • States flow: exited -> entering -> entered -> exiting -> exited
  • Supports render props for state-based class application

API

PropTypeDefaultDescription
presentboolean-Whether the element should be visible
durationnumber200Transition duration in milliseconds
onEntered() => void-Callback when enter completes
onExited() => void-Callback when exit completes