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

Add async for event #35

Merged
merged 1 commit into from
Dec 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ const RHFInput = ({
};

const eventWrapper = (event: EventFunction, eventName: string) => {
return (...arg: any) => {
const data = commonTask(event(arg));
return async (...arg: any) => {
const data = commonTask(await event(arg));
setValue(
name,
data,
Expand Down
8 changes: 5 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ export type ValidationOptions = Partial<{
| { value: Validate | Record<string, Validate>; message: string };
}>;

export type EventFunction = (
args: any,
) => {
type EventFunctionResult = {
value?: any;
checked?: boolean;
};

export type EventFunction = (
args: any,
) => EventFunctionResult | Promise<EventFunctionResult>;

export type Props = {
children?: React.ReactNode;
innerProps?: any;
Expand Down