0.1.7-alpha • Published 4 years ago

react-hook-form-wizard v0.1.7-alpha

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

react-hook-form-wizard

A simple wizard for react-hook-form

Inspired by Brian Yang's multi-step wizard and the wizard form example on the react-hook-form website

I'm still new to React so don't beat me up too bad. If you'd like to provide feedback or contribute please let me know. This is still in development.

Limitations

Currently only local storage is supported


Components Included

<Wizard>
    <Progress />
    <Pages>
        <Page>
            <YourCustomPageComponent />
        </Page>
        <Page>
            {(dataContext, formContext, wizardContext) => {
                -- Form fields go here with access to context methods via render prop --
            }}
        </Page>
    </Pages>
    <Navigation />
</Wizard>

Component API

Wizard
PropTypeRequiredDescription
useFormArgsObjectSame arguments passed into useForm, see useForm
initialPagenumberWhich page the wizard should start. Zero-based index.
onSubmit({ dataContext, formContext, wizardContext}) => voidYesThe submit function that will run on the final page of the form.
enableDevToolbooleanEnable DevTool component include in little-state-machine, see docs
Progress

This component is just for example purposes. Would likely not be used in a real-world scenario.

Pages

This component is a container component for Page components

Page

This component can contain your own components but also exposes render props for using included contexts. See basic usage example.

Navigation

This component is just for example purposes. Would likely not be used in a real-world scenario.


Hooks API

HookState / MethodsReturn / ArgumentDescription
useDataContextsee belowHooks into the little-state-machine store.
action(payload)(payload: Object) => voidMethod to update store state.
stateObjectReturns store state.
useFormContextsame as useFormsee docs for useFormContext
useWizardContextsee belowHooks into several states and methods for managing the wizard.
activePagenumberReturns the active page that the wizard is currently on. Zero-based index.
pageTotalnumberReturns the total number of Page components within the Pages component.
previousPage()() => {}Method for navigating to the previous page.
nextPage()() => {}Method for navigating to the next page.
goToPage(index)(index: number) => voidMethod for navigating to a particular page. Be careful for out of bounds.
isLastPagebooleanWhether the active page is the last page.

Basic Example

See Basic example demo

0.1.7-alpha

4 years ago

0.1.6-alpha

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago