Back to Slidev

Slide Hooks

docs/features/slide-hook.md

52.15.1715 B
Original Source

Slide Hooks

Slidev provides a set of hooks to help you manage the slide lifecycle:

ts
import { onSlideEnter, onSlideLeave, useIsSlideActive } from '@slidev/client'

const isActive = useIsSlideActive()

onSlideEnter((to, from) => {
  /* Called whenever the slide becomes active */
})

onSlideLeave((to, from) => {
  /* Called whenever the slide becomes inactive */
})

You can also use <LinkInline link="guide/global-context" /> to access other useful context information.

::: warning

In the slide component, onMounted and onUnmounted hooks are not available, because the component instance is preserved even when the slide is not active. Use onSlideEnter and onSlideLeave instead.

:::