Skip to main content
You are viewing Pre-Alpha documentation.
Vuetify0 Logo

useLazy

A composable for deferring content rendering until first activation, with optional reset on deactivation.

Intermediate100% coverageJan 11, 2026

Usage

The useLazy composable tracks whether content has been activated at least once. Content renders only after first activation (unless eager mode is enabled), reducing initial render cost for components like dialogs, menus, and tooltips.

isBooted: false · hasContent: false

Architecture

useLazy Lifecycle

Use controls to zoom and pan. Click outside or press Escape to close.

useLazy Lifecycle

API Reference

The following API details are for the useLazy composable.

Functions

useLazy

(active: MaybeRefOrGetter<boolean>, options?: LazyOptions) => LazyContext

Deferred content rendering for performance optimization.

Options

eager

MaybeRefOrGetter<boolean>

When true, content renders immediately without waiting for activation.

Default: false

Properties

isBooted

Readonly<ShallowRef<boolean>>

Whether the lazy content has been activated at least once.

hasContent

Readonly<Ref<boolean, boolean>>

Whether content should be rendered. True when: isBooted OR eager OR active

Methods

reset

() => void

Reset booted state. Call on leave transition if not eager.

onAfterLeave

() => void

Transition callback for after-leave. Resets if not eager.

Eager Mode

Use the eager option to render content immediately without waiting for activation:

ts
const { hasContent } = useLazy(isOpen, { eager: true })
// hasContent.value is always true

The eager option accepts a reactive value for dynamic control:

ts
const props = defineProps<{ eager: boolean }>()
const { hasContent } = useLazy(isOpen, {
  eager: toRef(() => props.eager),
})

Transition Integration

The onAfterLeave callback resets the lazy state after the leave transition completes (unless eager mode is enabled):

vue
<template>
  <Transition @after-leave="onAfterLeave">
    <div v-if="isOpen">
      <template v-if="hasContent">
        <!-- Heavy content -->
      </template>
    </div>
  </Transition>
</template>

This allows memory to be reclaimed when the content is hidden, while preserving the content during the leave animation.


© 2016-1970 Vuetify, LLC
Ctrl+/