Concepts
OverviewCompositionTestingLayout
Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridLink OverlayScrollableStackWrapComponents
AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltipUtilities
Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFrameHighlightJSON Tree ViewLocaleLocal StoragePortalPresenceShowsplitPropsThemeBy default the child component starts out as hidden and remains hidden after the present state is toggled off. This is
useful for situations where the element needs to be hidden initially and continue to stay hidden after its presence is
no longer required.
'use client'
import { Presence } from '@cerberus/react'import { useState } from 'react'
export const Basic = () => { const [present, setPresent] = useState(false) return ( <> <button type="button" onClick={() => setPresent(!present)}> Toggle </button> <Presence present={present}>Hidden and Hidden</Presence> </> )}To delay the mounting of a child component until the present prop is set to true, use the lazyMount prop:
'use client'
import { Presence } from '@cerberus/react'import { useState } from 'react'
export const LazyMount = () => { const [present, setPresent] = useState(false) return ( <> <button type="button" onClick={() => setPresent(!present)}> Toggle </button> <Presence present={present} lazyMount> Unmounted and Hidden </Presence> </> )}To remove the child component from the DOM when it's not present, use the unmountOnExit prop:
'use client'
import { Presence } from '@cerberus/react'import { useState } from 'react'
export const UnmountOnExit = () => { const [present, setPresent] = useState(false) return ( <> <button type="button" onClick={() => setPresent(!present)}> Toggle </button> <Presence present={present} unmountOnExit> Hidden and Unmounted on Exit </Presence> </> )}Both lazyMount and unmountOnExit can be combined for a component to be mounted only when it's present and to be
unmounted when it's no longer present:
'use client'
import { Presence } from '@cerberus/react'import { useState } from 'react'
export const LazyMountAndUnmountOnExit = () => { const [present, setPresent] = useState(false) return ( <> <button type="button" onClick={() => setPresent(!present)}> Toggle </button> <Presence present={present} lazyMount unmountOnExit> Lazy Mount and Unmounted on Exit </Presence> </> )}| Prop | Type | Required | Description |
|---|---|---|---|
asChild | boolean | No | Use the provided child element as the default rendered element, combining their props and behavior. |
immediate | boolean | No | Whether to synchronize the present change immediately or defer it to the next frame |
lazyMount | boolean | No | Whether to enable lazy mounting |
onExitComplete | VoidFunction | No | Function called when the animation ends in the closed state |
present | boolean | No | Whether the node is present (controlled by the user) |
skipAnimationOnMount | boolean | No | Whether to allow the initial presence animation. |
unmountOnExit | boolean | No | Whether to unmount on exit. |
On this page