Back to Shark UI

Presence

docs/utilities/presence

latest5.9 KB
Original Source

Sections

Components

Utilities

Forms

Hooks

Presence

Copy Markdown

Animate components on mount and unmount.

Docs

PreviewCode

Toggle

Installation#

CLIManual

pnpmbunnpmyarn

pnpm dlx shadcn@latest add @shark/presence

Usage#

import React from "react";
import { Presence } from "@/registry/react/components/presence";

const [visible, setVisible] = React.useState(false);

<Presence present={visible}>
  Content that animates in and out
</Presence>

Lazy#

Setting lazyMount and unmountOnExit to true lazy mounts and unmounts the content.

It will remove the element from the DOM when it is not present.

<Presence lazyMount unmountOnExit {...}>
</Presence>

States#

Presence automatically manages the attribute data-state to open and closed. This enables styling and animations based on visibility state.

<Presence present={true} /> // <div data-state="open" />
<Presence present={false} /> // <div data-state="closed" />

API Reference#

Presence#

PropTypeDefault
presentbooleanfalse
unmountOnExitbooleantrue
lazyMountbooleantrue
asChildbooleanfalse

For a complete list of props, see the Ark UI documentation.

[

Previous page

JSON Tree View ](/docs/utilities/json-tree-view)[

Next page

Show ](/docs/utilities/show)

On This Page

InstallationUsageLazyStatesAPI ReferencePresence