Skip to content

Commit d64ce36

Browse files
committed
update docs for alternate next page
1 parent e24bac2 commit d64ce36

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This should be used in combination with a component library and validation schem
88

99
All of the examples use react-hook-form, but any library could be used.
1010

11-
## Basic API
11+
## Basic Usage
1212

1313
- Create an array of pages and/or sequences. One for each page of the form.
1414
- Set up `react-hook-form`
@@ -38,7 +38,8 @@ const MyMultiPageForm = () => {
3838
currentPage, // the page object
3939
advance, // goes to the next page
4040
goBack, // goes back one page
41-
isFinal: // if this is the last page
41+
isFinal, // if this is the last page
42+
isFirst, // if this is the first page
4243
} = useMultiPageHookForm({
4344
hookForm,
4445
pages,
@@ -51,7 +52,7 @@ const MyMultiPageForm = () => {
5152
register={register}
5253
/>
5354

54-
{previousStep && <button onClick={goBack}>Prev</button>}
55+
{!isFirst && <button onClick={goBack}>Prev</button>}
5556
{!isFinal ? (
5657
<button onClick={advance}>Next</button>
5758
) : (
@@ -127,7 +128,8 @@ export function MyMultiPageForm() {
127128
currentPage,
128129
advance,
129130
goBack,
130-
isFinal
131+
isFinal,
132+
isFirst
131133
} = useMultiPageHookForm({
132134
hookForm,
133135
pages: sequence,
@@ -149,7 +151,7 @@ export function MyMultiPageForm() {
149151
/>
150152
</div>
151153
<div className="card">
152-
{previousStep && <button onClick={goBack}>Prev</button>}
154+
{!isFirst && <button onClick={goBack}>Prev</button>}
153155
{!isFinal ? (
154156
<button onClick={advance}>Next</button>
155157
) : (

docs/src/app/docs/api/page.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type HookFormPage<DataT, ComponentProps = { hookForm: UseFormReturn }> = {
2626
isFinal?: (data: Partial<DataT>) => boolean; // return true if this should be the final page of the form.
2727
isRequired?: (data: Partial<DataT>) => boolean | undefined; // Determines if this page is needed based on form data. Default: () => true
2828
validate?: (data: Partial<DataT>) => Promise<FieldErrors | undefined>; // Determines whether or not to continue.
29+
alternateNextPage: (data: Partial<DataT>) => pageId; // Useful if you need to override the default order of pages
2930

3031
// event handlers
3132
onArrive?: (data: Partial<DataT>) => void; // Function to execute upon arriving at this page.
@@ -140,7 +141,7 @@ export function MyMultiPageForm() {
140141
hookForm={hookForm}
141142
/>
142143

143-
{previousStep && <button onClick={goBack}>Prev</button>}
144+
{!isFirst && <button onClick={goBack}>Prev</button>}
144145
{!isFinal ? (
145146
<button onClick={advance}>Next</button>
146147
) : (

docs/src/app/docs/page.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ const MyMultiPageForm = () => {
128128
advance, // goes to the next page
129129
goBack, // goes back one page
130130
isFinal, // if this is the last page
131+
isFirst, // if this is the first page
131132
} = useMultiPageHookForm<FormSchema>({
132133
hookForm,
133134
pages: [mySequence, otherPage],
@@ -139,7 +140,7 @@ const MyMultiPageForm = () => {
139140
hookForm={hookForm}
140141
/>
141142
142-
{previousStep && <button onClick={goBack}>Prev</button>}
143+
{!isFirst && <button onClick={goBack}>Prev</button>}
143144
{!isFinal ? (
144145
<button onClick={advance}>Next</button>
145146
) : (

0 commit comments

Comments
 (0)