Skip to content

Commit fbc23b8

Browse files
author
Erik Rasmussen
committed
fix: add null guards on formState.values in getIn calls (TS2345)
1 parent 3b98a99 commit fbc23b8

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/useField.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function useField<
212212

213213
// Only update if the new initialValue differs from current form initial
214214
if (!isEqual(initialValue, currentFormInitial)) {
215-
const currentValue = getIn(formState.values, name);
215+
const currentValue = formState.values ? getIn(formState.values, name) : undefined;
216216

217217
// If the current value matches the new initial value, update the form's
218218
// initialValues to reflect this. This is needed for radio buttons where
@@ -271,7 +271,7 @@ function useField<
271271
// Fix #869: If name changed but state hasn't updated yet (effect hasn't run),
272272
// get the value directly from form values to avoid returning stale value
273273
let value = state.name !== name
274-
? getIn(form.getState().values, name)
274+
? getIn(form.getState().values ?? {}, name)
275275
: state.value;
276276

277277
// Handle null values first
@@ -308,7 +308,7 @@ function useField<
308308
const getInputChecked = () => {
309309
// Fix #869: Same as getInputValue - sync with current name
310310
let value = state.name !== name
311-
? getIn(form.getState().values, name)
311+
? getIn(form.getState().values ?? {}, name)
312312
: state.value;
313313
if (type === "checkbox") {
314314
value = parse(value, name);

0 commit comments

Comments
 (0)