mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-26 13:45:30 +03:00
feat(hooks): return setFieldValue from useField
This commit is contained in:
parent
c38f84733d
commit
2e26c97ae3
@ -173,15 +173,16 @@ export const useField = ({
|
|||||||
if (event) event(e);
|
if (event) event(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
/** ---------- NOTE(amine): Input Handlers ---------- */
|
const setFieldValue = (value) =>
|
||||||
const handleFieldChange = (e) =>
|
|
||||||
setState((prev) => ({
|
setState((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
value: e.target.value,
|
value,
|
||||||
error: undefined,
|
error: undefined,
|
||||||
touched: false,
|
touched: false,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
/** ---------- NOTE(amine): Input Handlers ---------- */
|
||||||
|
const handleFieldChange = (e) => setFieldValue(e.target.value);
|
||||||
const handleOnBlur = () => {
|
const handleOnBlur = () => {
|
||||||
// NOTE(amine): validate the inputs onBlur and touch the current input
|
// NOTE(amine): validate the inputs onBlur and touch the current input
|
||||||
let error = {};
|
let error = {};
|
||||||
@ -204,10 +205,10 @@ export const useField = ({
|
|||||||
if (!onSubmit) return;
|
if (!onSubmit) return;
|
||||||
setState((prev) => ({ ...prev, isSubmitting: true }));
|
setState((prev) => ({ ...prev, isSubmitting: true }));
|
||||||
onSubmit(state.value)
|
onSubmit(state.value)
|
||||||
.then(() => {
|
?.then(() => {
|
||||||
setState((prev) => ({ ...prev, isSubmitting: false }));
|
setState((prev) => ({ ...prev, isSubmitting: false }));
|
||||||
})
|
})
|
||||||
.catch(() => {
|
?.catch(() => {
|
||||||
setState((prev) => ({ ...prev, isSubmitting: false }));
|
setState((prev) => ({ ...prev, isSubmitting: false }));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -223,7 +224,7 @@ export const useField = ({
|
|||||||
onSubmit: handleFormOnSubmit,
|
onSubmit: handleFormOnSubmit,
|
||||||
});
|
});
|
||||||
|
|
||||||
return { getFieldProps, value: state.value, isSubmitting: state.isSubmitting };
|
return { getFieldProps, value: state.value, setFieldValue, isSubmitting: state.isSubmitting };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useIntersection = ({ onIntersect, ref }, dependencies = []) => {
|
export const useIntersection = ({ onIntersect, ref }, dependencies = []) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user