Skip to main content

Presence

Animation-aware mount/unmount. Delays unmounting until CSS exit animations complete.

import { Presence } from '@gentleduck/primitives/presence'
import { Presence } from '@gentleduck/primitives/presence'

Usage

<Presence present={isOpen}>
  <div className="my-animated-element">Content</div>
</Presence>
<Presence present={isOpen}>
  <div className="my-animated-element">Content</div>
</Presence>

Props

PropTypeDescription
presentbooleanWhether the child should be mounted
childrenReactElement | ((props: { present: boolean }) => ReactElement)Child element or render function

Render function form

For more control, use a render function:

<Presence present={isOpen}>
  {({ present }) => (
    <div className={present ? 'fade-in' : 'fade-out'}>
      Content
    </div>
  )}
</Presence>
<Presence present={isOpen}>
  {({ present }) => (
    <div className={present ? 'fade-in' : 'fade-out'}>
      Content
    </div>
  )}
</Presence>

State machine