enforces that changing a locale clears form state

This commit is contained in:
James
2020-04-21 14:11:15 -04:00
parent f1e6e2fb0b
commit cdc764cefe

View File

@@ -1,5 +1,6 @@
import { useContext, useCallback, useEffect } from 'react';
import FormContext from '../Form/Context';
import { useLocale } from '../../utilities/Locale';
import './index.scss';
@@ -12,6 +13,7 @@ const useFieldType = (options) => {
validate,
} = options;
const locale = useLocale();
const formContext = useContext(FormContext);
const { dispatchFields, submitted, processing } = formContext;
const mountValue = formContext.fields[name]?.value || null;
@@ -42,6 +44,10 @@ const useFieldType = (options) => {
if (defaultValue != null) sendField(defaultValue);
}, [defaultValue, sendField]);
useEffect(() => {
sendField(null);
}, [locale, sendField]);
const valid = formContext.fields[name] ? formContext.fields[name].valid : true;
const showError = valid === false && formContext.submitted;