Skip to content

Commit 1be99e8

Browse files
author
Sebastian Hoffmann
committed
feat(react): allow withForms render function to take extending properties
1 parent 411dd94 commit 1be99e8

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

packages/react-form/src/createFormHook.tsx

+22-11
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,31 @@ export interface WithFormProps<
198198
> {
199199
// Optional, but adds props to the `render` function outside of `form`
200200
props?: TRenderProps
201-
render: (
201+
render: <
202+
TFFormData extends TFormData,
203+
TFOnMount extends undefined | FormValidateOrFn<TFFormData>,
204+
TFOnChange extends undefined | FormValidateOrFn<TFFormData>,
205+
TFOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFFormData>,
206+
TFOnBlur extends undefined | FormValidateOrFn<TFFormData>,
207+
TFOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFFormData>,
208+
TFOnSubmit extends undefined | FormValidateOrFn<TFFormData>,
209+
TFOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFFormData>,
210+
TFOnServer extends undefined | FormAsyncValidateOrFn<TFFormData>,
211+
TFSubmitMeta,
212+
>(
202213
props: PropsWithChildren<
203214
NoInfer<TRenderProps> & {
204215
form: AppFieldExtendedReactFormApi<
205-
TFormData,
206-
TOnMount,
207-
TOnChange,
208-
TOnChangeAsync,
209-
TOnBlur,
210-
TOnBlurAsync,
211-
TOnSubmit,
212-
TOnSubmitAsync,
213-
TOnServer,
214-
TSubmitMeta,
216+
TFFormData,
217+
TFOnMount,
218+
TFOnChange,
219+
TFOnChangeAsync,
220+
TFOnBlur,
221+
TFOnBlurAsync,
222+
TFOnSubmit,
223+
TFOnSubmitAsync,
224+
TFOnServer,
225+
TFSubmitMeta,
215226
TFieldComponents,
216227
TFormComponents
217228
>

packages/react-form/tests/createFormHook.test-d.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,6 @@ describe('createFormHook', () => {
235235
const incorrectFormOpts = formOptions({
236236
defaultValues: {
237237
firstName: 'FirstName',
238-
lastName: 'LastName',
239-
firstNameWrong: 'FirstName',
240-
lastNameWrong: 'LastName',
241238
},
242239
})
243240

@@ -247,5 +244,19 @@ describe('createFormHook', () => {
247244
// @ts-expect-error Incorrect form opts
248245
<WithFormComponent form={incorrectAppForm} prop1="test" prop2={10} />
249246
)
247+
248+
const extendingFormOpts = formOptions({
249+
defaultValues: {
250+
firstName: 'FirstName',
251+
lastName: 'LastName',
252+
country: 'Country',
253+
},
254+
})
255+
256+
const extendingAppForm = useAppForm(extendingFormOpts)
257+
258+
const ExtendingFormOptsComponent = (
259+
<WithFormComponent form={extendingAppForm} prop1="test" prop2={10} />
260+
)
250261
})
251262
})

0 commit comments

Comments
 (0)