Skip to main content

ViewShotView

A NitroUI View whose ref captures what it renders.

import { ViewShotView, type ViewShotViewRef } from 'nitro-view-shot'
MemberSummary
ViewShotViewComponent; renders a View with every ViewProps.
ref.capture()Captures the view and its children as an Image.

Component​

function ViewShotView(props: ViewShotViewProps): JSX.Element

type ViewShotViewProps = ViewProps & { ref?: Ref<ViewShotViewRef> }

Renders a View from nitro-ui-renderer and forwards every prop except ref to it. Use layout, style and children exactly as on View. The ref receives a ViewShotViewRef instead of a ViewRef.

const shot = useRef<ViewShotViewRef>(null)

<ViewShotView ref={shot} layout={{ gap: 16 }} style={{ background: 'white' }}>
{children}
</ViewShotView>

capture()​

capture(): Promise<Image>

Captures this view and its children through ViewShot.capture. Resolves to a nitro-ui-renderer Image.

Rejects with:

MessageWhen
ViewShotView is not mounted.The view is not mounted.
Cannot capture a view with an empty size.The view has no width or height.

See Errors for every rejection.