Skip to content

Commit

Permalink
feat: onChange can handle undefined event
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasskk committed Sep 17, 2022
1 parent 13f89ef commit 788d039
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/react-pocket-form/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export type UseFormRegisterOptions<T = any, P extends Path<T> = any> = {
validateOn?: 'change' | 'blur' | 'submit'
revalidateOn?: 'change' | 'submit' | 'blur'
onChange?: (
element: Element,
element?: Element,
value?: PropertyType<T, P>
) => void | Promise<void>
onBlur?: (
Expand All @@ -117,7 +117,7 @@ export type UseFormRegister<T = any> = <P extends Path<T>>(
) => UseFormRegisterReturn<T, P>

export type UseFormRegisterReturn<T = any, P extends Path<T> = any> = {
onChange: (event: eventEl) => Promise<void> | void
onChange: (event?: eventEl) => Promise<void> | void
onBlur: (event: eventEl) => Promise<void> | void
ref: (el: Element, overrideValue?: PropertyType<T, P>) => void
name: string
Expand Down
2 changes: 1 addition & 1 deletion packages/react-pocket-form/src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export function useForm<T extends object = any>({

watchStore.get(name)?.()

await onChange?.(event.currentTarget, getValue(name))
await onChange?.(event?.currentTarget, getValue(name))
},
ref: async (element, overrideValue) => {
const refValue = refStore.get(name)
Expand Down

0 comments on commit 788d039

Please sign in to comment.