mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 20:01:59 +00:00
Hot fixed and format code
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user