/** * useWizard Hook * * Primary hook for accessing wizard context. * Provides all wizard functionality to step components. */ import { useContext } from 'react'; import { WizardContext } from './WizardProvider'; import type { WizardContextValue } from './types'; /** * Hook to access wizard context * * @throws Error if used outside of WizardProvider * * @example * ```tsx * function MyStepComponent() { * const { * data, * updateField, * next, * prev, * errors, * isValidating, * } = useWizard(); * * return ( *
* updateField('name', e.target.value)} * /> * {errors.name && {errors.name}} * * *
* ); * } * ``` */ export function useWizard< TData extends Record = Record >(): WizardContextValue { const context = useContext(WizardContext); if (!context) { throw new Error( 'useWizard must be used within a WizardProvider. ' + 'Wrap your component tree with .' ); } return context as WizardContextValue; }