From fbc23b83a288689b022ab82ec8dbaa78115130a5 Mon Sep 17 00:00:00 2001 From: Erik Rasmussen Date: Tue, 5 May 2026 10:09:01 +0200 Subject: [PATCH] fix: add null guards on formState.values in getIn calls (TS2345) --- src/useField.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/useField.ts b/src/useField.ts index cf20e13..db7b27a 100644 --- a/src/useField.ts +++ b/src/useField.ts @@ -212,7 +212,7 @@ function useField< // Only update if the new initialValue differs from current form initial if (!isEqual(initialValue, currentFormInitial)) { - const currentValue = getIn(formState.values, name); + const currentValue = formState.values ? getIn(formState.values, name) : undefined; // If the current value matches the new initial value, update the form's // initialValues to reflect this. This is needed for radio buttons where @@ -271,7 +271,7 @@ function useField< // Fix #869: If name changed but state hasn't updated yet (effect hasn't run), // get the value directly from form values to avoid returning stale value let value = state.name !== name - ? getIn(form.getState().values, name) + ? getIn(form.getState().values ?? {}, name) : state.value; // Handle null values first @@ -308,7 +308,7 @@ function useField< const getInputChecked = () => { // Fix #869: Same as getInputValue - sync with current name let value = state.name !== name - ? getIn(form.getState().values, name) + ? getIn(form.getState().values ?? {}, name) : state.value; if (type === "checkbox") { value = parse(value, name);