API ReferenceuseTrailManager

useTrailManager

Package: @trailguide/runtime

The high-level hook for managing a tour’s full lifecycle — first-visit auto-show, completion tracking, loading state gates, resume support, and all callbacks.

Usage

import { useTrailManager, Trailguide } from '@trailguide/runtime'
import { onboardingTour } from './tours'
 
export default function DashboardPage() {
  const { isActive, dismiss } = useTrailManager(onboardingTour, {
    once: true,
    delay: 600,
  })
 
  return (
    <>
      {/* page content */}
      {isActive && (
        <Trailguide
          trail={onboardingTour}
          onComplete={dismiss}
          onSkip={dismiss}
        />
      )}
    </>
  )
}

Options

OptionTypeDefaultDescription
oncebooleanfalseAuto-show on first visit only. Marks the tour as completed on dismiss so it never auto-shows again.
storageKeystring'trailguide:managed:{trail.id}'localStorage key for completion and progress. Override to re-show after major redesigns.
enabledbooleantrueGate auto-show on this condition. Useful for deferring until data is loaded.
delaynumber500Milliseconds to wait after mount (or enabled turning true) before auto-showing.
resumablebooleanfalseSave step progress on each transition and resume from the last step.
onComplete() => voidCalled when the user finishes the last step.
onSkip() => voidCalled when the user clicks the × button.
onAbandoned() => voidCalled when stop() is called while the tour is active (e.g. navigation).
onStepChange(step, index) => voidCalled on every step transition.
onError(step, error) => voidCalled when a step’s target is not found or not visible.
analyticsAnalyticsConfigEnable Pro analytics.

Return value

PropertyTypeDescription
isActivebooleanWhether the tour is currently running.
currentStepStep | nullThe step currently being shown, or null if inactive.
currentStepIndexnumber0-based index of the current step.
totalStepsnumberTotal number of steps in the tour.
show() => voidShow the tour (resumes from saved progress if resumable: true).
dismiss() => voidHide the tour. If once: true, also marks it as completed.
reset() => voidClear all saved state so the tour will auto-show again.
next() => voidAdvance to the next step.
prev() => voidGo back to the previous step.
skip() => voidSkip the tour.
goToStep(index: number) => voidJump to a specific step.

Notes

  • Callbacks are stored in refs internally, so you can pass new function references each render without restarting the tour.
  • The auto-show timer is cleared and restarted whenever enabled or delay changes.
  • If once: true and tourStorage.hasCompleted(storageKey) is true on mount, the tour never auto-shows (but show() still works).
  • For help menu integration, use useRegisterTour instead — it’s a drop-in replacement that also registers with TourRegistryProvider.