Rehooks

useStep

Manages step-based navigation with imperative controls. Returns step navigation methods and state.

useStep

Installation

npx rehooks-cli@latest add useStep

Usage

Component.tsx
import { useStep } from "~/hooks/useStep";
 
function Component() {
  const { currentStep, nextStep, prevStep, jumpTo, isFirstStep, isLastStep } =
    useStep({
      totalSteps: 5,
      initialStep: 2,
    });
 
  return (
    <div>
      <div>Current step: {currentStep}</div>
      <button onClick={prevStep}>Prev</button>
      <button onClick={nextStep}>Next</button>
      <button onClick={() => jumpTo(3)}>Jump to 3</button>
      <button onClick={() => jumpTo(0)}>Jump to 0</button>
      <button onClick={() => jumpTo(4)}>Jump to 4</button>
      <div>Is first step: {isFirstStep ? "yes" : "no"}</div>
      <div>Is last step: {isLastStep ? "yes" : "no"}</div>
    </div>
  );
}

API

useStep

useStep.ts
function useStep<T = number>(config: UseStepProps<T>): UseStepReturn<T>;

Manages step-based navigation with imperative controls. Returns step navigation methods and state.

Parameters

NameTypeDescription
configUseStepPropsThe configuration for the step management.
config.totalStepsnumberTotal number of steps (required if steps not provided)
config.stepsT[]Array of custom step identifiers (required if totalSteps not provided)
config.initialStepTInitial step identifier (defaults to first step)

Returns

NameTypeDescription
currentStepT
nextStepvoid
prevStepvoid
jumpTovoid
isFirstStepboolean

On this page