Components
WizardProvider

WizardProvider

The main context provider that manages form state and logic.

Props

PropTypeRequiredDescription
configWizardConfigYesForm configuration
fieldComponentsFieldComponentsMapYesMap of field type to component
onComplete(data) => voidNoCalled when form is submitted
onStepChange(step, data) => voidNoCalled when step changes
initialDataRecord<string, any>NoPre-fill form data
themeThemeNoCustom theme

Basic Usage

import { WizardProvider, WizardContainer, defaultFieldComponents } from '@better_form/core';
 
function MyForm() {
  return (
    <WizardProvider
      config={config}
      fieldComponents={defaultFieldComponents}
      onComplete={(data) => console.log('Submitted:', data)}
    >
      <WizardContainer />
    </WizardProvider>
  );
}

With Initial Data

<WizardProvider
  config={config}
  fieldComponents={defaultFieldComponents}
  initialData={{
    email: 'user@example.com',
    country: 'IT',
  }}
>
  <WizardContainer />
</WizardProvider>

With Custom Components

import { WizardProvider, defaultFieldComponents } from '@better_form/core';
import { MyCustomField } from './components/MyCustomField';
 
const fieldComponents = {
  ...defaultFieldComponents,
  'custom-field': MyCustomField,
};
 
<WizardProvider config={config} fieldComponents={fieldComponents}>
  <WizardContainer />
</WizardProvider>

Callbacks

<WizardProvider
  config={config}
  fieldComponents={defaultFieldComponents}
  onComplete={(data) => {
    // Handle form submission
    fetch('/api/submit', {
      method: 'POST',
      body: JSON.stringify(data),
    });
  }}
  onStepChange={(stepIndex, formData) => {
    // Track step changes
    analytics.track('step_change', { step: stepIndex });
  }}
>
  <WizardContainer />
</WizardProvider>