Appearance
useStepper
Provides helpers for building a multi-step wizard interface.
Demo
Usage
Steps as array
tsx
import { useStepper } from '@reause/core'
const {
index,
setIndex,
steps,
stepNames,
current,
next,
previous,
isFirst,
isLast,
goTo,
goToNext,
goToPrevious,
goBackTo,
isNext,
isPrevious,
isCurrent,
isBefore,
isAfter,
} = useStepper([
'billing-address',
'terms',
'payment',
])
// Access the step through `current`
console.log(current) // 'billing-address'Type Declarations
ts
export interface UseStepperReturn<StepName, Steps, Step> {
index: number;
setIndex: Dispatch<SetStateAction<number>>;
steps: Steps;
stepNames: StepName[];
current: Step;
next: StepName | undefined;
previous: StepName | undefined;
isFirst: boolean;
isLast: boolean;
at: (index: number) => Step | undefined;
get: (step: StepName) => Step | undefined;
goTo: (step: StepName) => void;
goToNext: () => void;
goToPrevious: () => void;
goBackTo: (step: StepName) => void;
isNext: (step: StepName) => boolean;
isPrevious: (step: StepName) => boolean;
isCurrent: (step: StepName) => boolean;
isBefore: (step: StepName) => boolean;
isAfter: (step: StepName) => boolean;
}
export function useStepper<T extends string | number>(steps: T[], initialStep?: T): UseStepperReturn<T, T[], T>