Join our Discord Community

React useStep Hook

React useStep hook for step navigation. Manage multi-step processes with automatic boundary checking and progress tracking using TypeScript for Next.js apps.

Building complex wizard or stepper flows?

Join our Discord community for help from other developers.


Ever tried to manage step navigation in React and ended up with manual step counting chaos, boundary checking nightmares, or broken wizard state management? You know the drill—manually incrementing step numbers, forgetting to check minimum/maximum boundaries, dealing with step validation logic, handling reset functionality. This free open source React useStep custom hook handles all that step management complexity so you can focus on building smooth workflows instead of debugging navigation edge cases in your React applications.

useStep showcase

Smart step navigation with automatic boundary validation and progress tracking:

Loading component...

This free open source React hook simplifies multi-step process management with TypeScript support for modern JavaScript applications. Whether you're building onboarding flows, form wizards, or checkout processes in your Next.js projects, this React hook keeps your step navigation reliable and user-friendly.

Installation

npx shadcn@latest add https://www.shadcn.io/registry/use-step.json
npx shadcn@latest add https://www.shadcn.io/registry/use-step.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/use-step.json
bunx shadcn@latest add https://www.shadcn.io/registry/use-step.json

Why most step navigation implementations suck

Look, you could keep manually managing step state with useState and boundary checking. But then you hit the step navigation complexity—off-by-one errors, forgotten boundary validation, inconsistent navigation patterns, performance issues from re-creating functions in React applications.

Most developers manually track step counts with useState without proper boundary checking, leading to navigation bugs when users reach edge cases in TypeScript components. Or they create new callback functions on every render, causing unnecessary re-renders and performance issues. Some forget to handle edge cases like jumping to invalid steps or resetting to the beginning in Next.js projects.

This React hook uses optimized step management under the hood, with automatic boundary checking and memoized navigation functions in JavaScript applications. The browser handles all the state updates, plus you get comprehensive validation and helper methods in one call.

Plus it handles all the edge cases—boundary validation with descriptive errors, memoized callbacks for performance, flexible step setting with functional updates in React development. No more broken step navigation or inconsistent wizard behavior.

This free open source React hook manages step state while you focus on building features. Whether you're creating React applications, Next.js interfaces, or TypeScript components, reliable step navigation keeps your JavaScript development smooth.

Features

  • Step navigation with automatic boundary checking and comprehensive validation in React applications
  • Convenient helpers including goToNextStep, goToPrevStep, and reset methods in TypeScript components
  • Boundary validation preventing invalid step transitions with boolean flags in Next.js projects
  • Type safety with comprehensive TypeScript definitions and error handling for JavaScript development
  • Flexible step setting supporting both direct values and function updates for React frameworks
  • Memory efficient with proper callback memoization to prevent unnecessary re-renders in modern applications
  • Free open source designed for modern React development workflows

When you'll actually use this

Real talk—this isn't for simple page navigation in React applications. React Router handles route-based flows perfectly. But when you need stateful step management within a component or complex wizard logic, this React hook delivers in Next.js projects.

Perfect for:

  • Onboarding sequences - Guide users through registration, setup, or tutorial flows built with TypeScript
  • Form wizards - Break complex forms into digestible, validated steps using React patterns
  • Checkout processes - Navigate through cart, shipping, payment, and confirmation in JavaScript applications
  • Installation guides - Step-by-step software configuration or setup processes in React components
  • Survey flows - Multi-page questionnaires with conditional logic in Next.js applications
  • Tutorial systems - Interactive guided tours with progress tracking using TypeScript safety

API Reference

useStep

useStep(maxStep: number): [number, UseStepActions]
ParameterTypeDescription
maxStepnumberThe maximum step in the process (must be >= 1)

Return Value

Returns a tuple: [currentStep, actions]

IndexTypeDescription
[0]numberCurrent step number (1-based indexing)
[1]UseStepActionsObject containing navigation methods and state flags

UseStepActions

PropertyTypeDescription
canGoToNextStepbooleanWhether navigation to next step is possible
canGoToPrevStepbooleanWhether navigation to previous step is possible
goToNextStep() => voidMemoized function to advance to the next step
goToPrevStep() => voidMemoized function to go back to the previous step
reset() => voidMemoized function to reset to step 1
setStepDispatch<SetStateAction<number>>Direct step setter with boundary validation

Common gotchas

Boundary checking is automatic: The React hook prevents navigation beyond the defined step range (1 to maxStep) in React applications. goToNextStep and goToPrevStep will not execute if they would result in invalid step numbers, and the boolean flags reflect this state.

Step numbering starts at 1: Unlike array indexing, steps use 1-based numbering to match user interface conventions in TypeScript components. This makes it intuitive when displaying "Step 1 of 5" but remember to adjust if using with 0-based arrays.

Functions are memoized for performance: All navigation functions maintain stable references across re-renders using useCallback in Next.js projects. This prevents unnecessary re-renders of child components but means they're safe to include in dependency arrays.

setStep validates boundaries: The direct setter function automatically clamps values to the valid range in JavaScript applications. Setting a step below 1 will result in step 1, and setting above maxStep will result in the maximum step.

Step changes trigger re-renders: Every step navigation will cause component re-renders in React frameworks. Consider memoizing expensive child components that don't need to update on step changes.

Initial step is always 1: The React hook always starts at step 1 and doesn't support custom initial steps in TypeScript projects. Use setStep() in useEffect if you need to start at a different step.

Questions you might have