Skip to content
This repository was archived by the owner on Jan 14, 2021. It is now read-only.

Commit a792f4b

Browse files
JeromeDeLeonbluebill1049
authored andcommitted
Add async for event (#35)
1 parent 934c790 commit a792f4b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ const RHFInput = ({
6363
};
6464

6565
const eventWrapper = (event: EventFunction, eventName: string) => {
66-
return (...arg: any) => {
67-
const data = commonTask(event(arg));
66+
return async (...arg: any) => {
67+
const data = commonTask(await event(arg));
6868
setValue(
6969
name,
7070
data,

src/types.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ export type ValidationOptions = Partial<{
2121
| { value: Validate | Record<string, Validate>; message: string };
2222
}>;
2323

24-
export type EventFunction = (
25-
args: any,
26-
) => {
24+
type EventFunctionResult = {
2725
value?: any;
2826
checked?: boolean;
2927
};
3028

29+
export type EventFunction = (
30+
args: any,
31+
) => EventFunctionResult | Promise<EventFunctionResult>;
32+
3133
export type Props = {
3234
children?: React.ReactNode;
3335
innerProps?: any;

0 commit comments

Comments
 (0)