Skip to content

useTour()

Hook that provides tour state and control methods.

Usage

tsx
import { useTour } from '@guideflow/react'

function MyComponent() {
  const { start, stop, next, prev, isActive, currentStepIndex, totalSteps } = useTour()

  return (
    <div>
      <button onClick={() => start(flow)}>Start Tour</button>
      {isActive && (
        <div>
          <span>Step {currentStepIndex + 1} of {totalSteps}</span>
          <button onClick={prev}>Back</button>
          <button onClick={next}>Next</button>
          <button onClick={stop}>Close</button>
        </div>
      )}
    </div>
  )
}

Return Value

PropertyTypeDescription
start(flow: FlowDefinition) => voidStart a tour
stop() => voidStop the active tour
next() => voidAdvance to the next step
prev() => voidGo to the previous step
isActivebooleanWhether a tour is currently running
currentStepIndexnumberZero-based index of the current step
totalStepsnumberTotal number of steps
currentStepIdstring | nullID of the current step

Requirements

Must be used inside a <TourProvider>.

Released under the MIT License.