Skip to content

Commit

Permalink
feat(hook): Enhanced handleSubmit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Nov 3, 2021
1 parent 5a1623a commit ea2ccb2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/hook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export declare function useValidator(props?: UseValidator): {
validator: Validator;
forceUpdate: () => void;
/** Only `Form` Support */
handleSubmit: (handle?: ((value: Values) => void) | undefined) => (evn: React.FormEvent<HTMLFormElement>) => void;
handleSubmit: (handle?: ((value: Values, valid: boolean) => void) | undefined) => (evn: React.FormEvent<HTMLFormElement>) => void;
/** Only `Form` Support */
handleReset: (handle?: ((value: Values) => void) | undefined) => (evn: React.FormEvent<HTMLFormElement>) => void;
};
Expand Down
6 changes: 3 additions & 3 deletions packages/hook/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export function useValidator(props: UseValidator = {}) {
}, [props.form, validator.current]);

const handleForceUpdate = () => forceUpdate(upState + 1);
const handleSubmit = (handle?: (value: Values) => void) => (evn: React.FormEvent<HTMLFormElement>) => {
const handleSubmit = (handle?: (value: Values, valid: boolean) => void) => (evn: React.FormEvent<HTMLFormElement>) => {
evn && evn.preventDefault();
validator.current.showMessages();
forceUpdate(upState + 1);
if (handle) {
const val = validator.current.values;
handle({ ...validator.current.values });
const valid = validator.current.allValid();
handle({ ...validator.current.values }, valid);
}
}
const handleReset = (handle?: (value: Values) => void) => (evn: React.FormEvent<HTMLFormElement>) => {
Expand Down

0 comments on commit ea2ccb2

Please sign in to comment.