From c1dc1a27856ee3fcada41916470ebb672f10be8b Mon Sep 17 00:00:00 2001 From: Misha Moroshko Date: Fri, 16 Apr 2021 11:58:09 +1000 Subject: [PATCH] Cleanup --- src/components/Form.js | 31 ++++++++++++---------- website/src/pages/components/form/index.js | 4 +-- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/components/Form.js b/src/components/Form.js index 7e8599c0..4f2b0215 100644 --- a/src/components/Form.js +++ b/src/components/Form.js @@ -229,15 +229,20 @@ function Form(_props) { }; const setErrors = useCallback((errorsMap) => { setState((state) => { - const newErrors = Object.keys(fields.current).reduce((acc, name) => { - if (typeof errorsMap[name] === "string") { - return setPath(acc, name, [errorsMap[name]]); - } - if (Array.isArray(errorsMap[name])) { - return setPath(acc, name, errorsMap[name]); - } - return acc; - }, {...state.errors}); + const newErrors = Object.keys(fields.current).reduce( + (acc, name) => { + if (typeof errorsMap[name] === "string") { + return setPath(acc, name, [errorsMap[name]]); + } + + if (Array.isArray(errorsMap[name])) { + return setPath(acc, name, errorsMap[name]); + } + + return acc; + }, + { ...state.errors } + ); return { ...state, @@ -246,13 +251,11 @@ function Form(_props) { }); }, []); const resetForm = ({ values, errors } = {}) => { - setState({ + setState((state) => ({ + ...state, values: values ?? initialValues, errors: errors ?? initialErrors ?? {}, - shouldValidateOnChange: false, - namesToValidate: null, - submitStatus: "READY", - }); + })); }; const responsiveFormCSS = useResponsivePropsCSS(props, DEFAULT_PROPS, { width: responsiveSize("width"), diff --git a/website/src/pages/components/form/index.js b/website/src/pages/components/form/index.js index 17a7d1de..6c1f23eb 100644 --- a/website/src/pages/components/form/index.js +++ b/website/src/pages/components/form/index.js @@ -136,7 +136,7 @@ function FormPage() { return (
- + About you