handleSubmit

Creates a submit event handler for the form that prevents default browser submission, validates the form input, and calls the provided handler if validation succeeds. This is designed to be used with the form's onsubmit event.

const result = handleSubmit<TSchema>(form, handler);

In React Native, where there is no form element or submit event, handleSubmit returns a plain async function that you call from a button's onPress or a text input's onSubmitEditing handler. In this case the handler receives only the validated form output — there is no event object.

Generics

Parameters

Explanation

The form parameter is the form store to handle submission for. The handler parameter can be a SubmitHandler (no event) or, in the frameworks that submit through a form element, a SubmitEventHandler (with event) that gets called with the validated form output if validation succeeds. In React Native only SubmitHandler applies, as there is no submit event.

If the input changes, the form is fully reset, or a newer validation or submission starts before validation finishes, the outdated submission does not call its handler.

A newer submission or full form reset also prevents an older handler from changing form errors or isSubmitting when it finishes. This does not abort a handler or network request that has already started.

Returns

  • result (() => Promise<void>) | ((event: SubmitEvent) => Promise<void>)

Primitives

Methods

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of @fabian-hiller

Partners

Thanks to our partners who support the project ideally and financially.

Sponsors

Thanks to our GitHub sponsors who support the project financially.

  • GitHub profile picture of @vasilii-kovalev
  • GitHub profile picture of @UpwayShop
  • GitHub profile picture of @ruiaraujo012
  • GitHub profile picture of @hyunbinseo
  • GitHub profile picture of @nickytonline
  • GitHub profile picture of @kibertoad
  • GitHub profile picture of @caegdeveloper
  • GitHub profile picture of @Thanaen
  • GitHub profile picture of @bmoyroud
  • GitHub profile picture of @ysknsid25
  • GitHub profile picture of @dslatkin