useTourContext
Low-level hook returning the raw TourContext value. Use useTour for typical tour control; useTourContext for custom integrations.
Low-level access to the raw TourContext value. Most consumers should use useTour — useTourContext is the escape hatch when you need direct access to context internals (custom hooks, testing, headless integrations).
Usage
import { useTourContext } from '@tour-kit/core';
function CustomTourBridge() {
const ctx = useTourContext();
// ctx is TourContextValue — full state machine + actions
return <span>Step: {ctx.state.currentStepIndex}</span>;
}useTourContext throws if no <TourProvider> is mounted above. Use useTourContextOptional if rendering inside a tree that may or may not have a provider.
Return Value
Returns TourContextValue — the full state + actions object. See Types for the complete shape.
| Field | Type | Description |
|---|---|---|
state | TourState | Current tour state machine |
actions | TourActions | All tour actions (start, next, prev, skip, complete, ...) |
config | TourKitConfig | Resolved configuration |
useTourContextOptional
Same as useTourContext but returns null instead of throwing when no provider is present. Useful for components that may render outside a tour context.
import { useTourContextOptional } from '@tour-kit/core';
function ContextAwareButton() {
const ctx = useTourContextOptional();
if (!ctx) return <button>Static</button>;
return <button onClick={ctx.actions.next}>Next</button>;
}Returns TourContextValue | null.
For ergonomic tour control, prefer useTour. It wraps useTourContext and exposes a flatter API (isActive, currentStep, start, next, ...).