Hot fixed and format code

This commit is contained in:
2023-11-03 10:18:57 +07:00
parent 48af6272b3
commit ae7c25e6f3
11 changed files with 46 additions and 38 deletions
+8 -8
View File
@@ -21,7 +21,7 @@ const useForm = (
stateSchema = {},
stateValidatorSchema = {} as TValidator,
submitFormCallback: (values: TKeyValue) => void,
initialValue: string = ''
initialValue: string = '',
) => {
const [values, setValues] = useState<TKeyValue>(INITIAL_STATE_SCHEMA);
const [errors, setErrors] = useState(getPropValues(stateSchema, ERROR));
@@ -73,7 +73,7 @@ const useForm = (
return error;
},
[stateValidatorSchema]
[stateValidatorSchema],
);
// Set Initial Error State
@@ -86,10 +86,10 @@ const useForm = (
[name]: !initialValue // Skip error when initialValue have values
? validateFormFields(name, values[name] as string)
: '',
}))
})),
);
},
[errors, values, validateFormFields]
[errors, values, validateFormFields],
);
// Used to disable submit button if there's a value in errors
@@ -98,7 +98,7 @@ const useForm = (
// in every re-render in component
const validateErrorState = useCallback(
() => Object.values(errors).some((error) => error),
[errors]
[errors],
);
// For every changed in our state this will be fired
@@ -114,7 +114,7 @@ const useForm = (
(
event: ChangeEvent<
HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement
>
>,
) => {
setIsDirty(true);
@@ -136,7 +136,7 @@ const useForm = (
setErrors((prevState) => ({ ...prevState, [name]: error }));
isValid((prevState) => ({ ...prevState, [name]: true }));
},
[validateFormFields]
[validateFormFields],
);
const handleOnSubmit = useCallback(
@@ -152,7 +152,7 @@ const useForm = (
setDisable(true);
}
},
[validateErrorState, submitFormCallback, values]
[validateErrorState, submitFormCallback, values],
);
return {