Skip to content

Commit

Permalink
feat: support onSubmit returning void
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanfilhoz committed May 14, 2024
1 parent 6f6ef94 commit 843492f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "safe-form",
"version": "0.10.0",
"version": "0.10.1",
"description": "⚡️ End-to-end type-safety from client to server.",
"main": "dist/safe-form.es.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 4 additions & 2 deletions src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type UseFormParams<Input extends FormInput, FormResponse> = {
initialValues?: Partial<Input>
validateOnBlur?: boolean
validateOnChange?: boolean
onSubmit?: (input: Input) => boolean | Promise<boolean>
onSubmit?: (input: Input) => boolean | void | Promise<boolean | void>
onSuccess?: (response: FormResponse) => void
onError?: (
error: string | null,
Expand Down Expand Up @@ -289,7 +289,9 @@ export const useForm = <Input extends FormInput, FormResponse>({
// If there is an onSubmit callback, call it
if (onSubmit) {
const shouldSubmit = await onSubmit(input)
if (!shouldSubmit) return

// If the callback explicitly returns false, skip the server action
if (shouldSubmit === false) return
}

// Submit the server action
Expand Down

0 comments on commit 843492f

Please sign in to comment.