Skip to content

Commit

Permalink
fix: add async await to use controller onchange
Browse files Browse the repository at this point in the history
  • Loading branch information
aashishsingla567 committed Nov 8, 2023
1 parent 8f80f4c commit eed0d6f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/types/controller.ts
Expand Up @@ -7,7 +7,6 @@ import {
FieldPath,
FieldPathValue,
FieldValues,
Noop,
RefCallBack,
UseFormStateReturn,
} from './';
Expand All @@ -23,8 +22,8 @@ export type ControllerRenderProps<
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
> = {
onChange: (...event: any[]) => void;
onBlur: Noop;
onChange: (...event: any[]) => Promise<void | boolean>;
onBlur: () => Promise<void | boolean>;
value: FieldPathValue<TFieldValues, TName>;
disabled?: boolean;
name: TName;
Expand Down
4 changes: 2 additions & 2 deletions src/useController.ts
Expand Up @@ -131,7 +131,7 @@ export function useController<
? { disabled: formState.disabled || disabled }
: {}),
onChange: React.useCallback(
(event) =>
async (event) =>
_registerProps.current.onChange({
target: {
value: getEventValue(event),
Expand All @@ -142,7 +142,7 @@ export function useController<
[name],
),
onBlur: React.useCallback(
() =>
async () =>
_registerProps.current.onBlur({
target: {
value: get(control._formValues, name),
Expand Down

0 comments on commit eed0d6f

Please sign in to comment.