feat: initializes useField internalValue with incoming field value
This commit is contained in:
@@ -33,17 +33,17 @@ const useField = <T extends unknown>(options: Options): FieldType<T> => {
|
||||
setModified,
|
||||
} = formContext || {};
|
||||
|
||||
const [internalValue, setInternalValue] = useState(undefined);
|
||||
const [internallyValid, setInternallyValid] = useState<boolean>(undefined);
|
||||
|
||||
// Debounce internal values to update form state only every 60ms
|
||||
const debouncedValue = useDebounce(internalValue, 120);
|
||||
|
||||
// Get field by path
|
||||
const field = getField(path);
|
||||
|
||||
const initialValue = field?.initialValue as T;
|
||||
|
||||
const [internalValue, setInternalValue] = useState(field?.value as T);
|
||||
const [internallyValid, setInternallyValid] = useState<boolean>(undefined);
|
||||
|
||||
// Debounce internal values to update form state only every 60ms
|
||||
const debouncedValue = useDebounce(internalValue, 120);
|
||||
|
||||
// Validation is defined by two ways -
|
||||
// 1. by field state
|
||||
// 2. maintained locally to reflect instant validation state changes
|
||||
@@ -128,7 +128,6 @@ const useField = <T extends unknown>(options: Options): FieldType<T> => {
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
setInternalValue(initialValue);
|
||||
setInternallyValid(undefined);
|
||||
}, [initialValue]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user