useFormStepsInfo
Computes rich metadata for every step — status, error counts, completion, progress percentage. Designed to power UI components like progress bars, tab navigators, and step indicators.
This is the most useful hook for custom UI. Unlike the other hooks, you’ll often use this one directly when building a custom step progress component.
Signature
import { useFormStepsInfo } from '@saastro/forms';
const info = useFormStepsInfo({ steps, currentStepId, stepHistory, fields });
Must be called inside a React Hook Form
FormProvider(it readsuseFormContext()for error state).
Parameters
| Parameter | Type | Description |
|---|---|---|
steps | Steps | Steps configuration map |
currentStepId | string | Active step ID |
stepHistory | string[] | Stack of visited step IDs |
fields | Fields | Field definitions map |
Return Value: FormStepsInfo
| Property | Type | Description |
|---|---|---|
steps | StepInfo[] | Metadata for every step (see below) |
currentStepId | string | Active step ID |
totalSteps | number | Total number of steps |
completedSteps | number | Count of completed steps |
progress | number | Completion percentage (0-100) |
stepHistory | string[] | Stack of visited step IDs |
canGoNext | boolean | Whether forward navigation is possible |
canGoPrev | boolean | Whether back navigation is possible |
getStepInfo(id) | (string) => StepInfo | Get info for a specific step |
getStepStatus(id) | (string) => StepStatus | Get status for a specific step |
StepInfo
| Property | Type | Description |
|---|---|---|
id | string | Step ID |
fields | string[] | Field names in this step |
fieldCount | number | Number of fields |
status | StepStatus | 'pending', 'current', 'completed', or 'error' |
hasErrors | boolean | Whether any fields have validation errors |
errorCount | number | Number of fields with errors |
isVisited | boolean | Whether the step has been visited |
isCurrent | boolean | Whether this is the active step |
isCompleted | boolean | Visited, not current, no errors, all fields valid |
canNavigate | boolean | Whether the user can navigate to this step |
StepStatus
type StepStatus = 'pending' | 'current' | 'completed' | 'error';
'pending'— Not yet visited'current'— Active step'completed'— Visited, all fields valid'error'— Visited, has validation errors
Example: Custom Progress Bar
import { useFormStepsInfo } from '@saastro/forms';
function StepProgress({ steps, currentStepId, stepHistory, fields }) {
const info = useFormStepsInfo({ steps, currentStepId, stepHistory, fields });
return (
<div>
<div className="flex gap-2 mb-4">
{info.steps.map((step) => (
<div
key={step.id}
className={`flex-1 h-2 rounded ${
step.isCompleted
? 'bg-green-500'
: step.isCurrent
? 'bg-blue-500'
: step.hasErrors
? 'bg-red-500'
: 'bg-gray-200'
}`}
/>
))}
</div>
<p className="text-sm text-muted-foreground">
Step {info.steps.findIndex((s) => s.isCurrent) + 1} of {info.totalSteps} ({info.progress}%
complete)
</p>
</div>
);
}
Example: Step Navigator with Error Badges
function StepNav({ steps, currentStepId, stepHistory, fields, onStepClick }) {
const info = useFormStepsInfo({ steps, currentStepId, stepHistory, fields });
return (
<nav className="flex gap-1">
{info.steps.map((step, i) => (
<button
key={step.id}
onClick={() => step.canNavigate && onStepClick(step.id)}
disabled={!step.canNavigate}
className={`px-3 py-1 rounded text-sm ${
step.isCurrent
? 'bg-primary text-white'
: step.isCompleted
? 'bg-green-100 text-green-800'
: 'bg-gray-100 text-gray-500'
}`}
>
{i + 1}. {step.id}
{step.hasErrors && <span className="ml-1 text-xs text-red-500">({step.errorCount})</span>}
</button>
))}
</nav>
);
}
Related
- Multi-Step Forms — Full guide on step configuration
- useFormSteps — The navigation logic this hook reads from