diff --git a/src/useFormStates.ts b/src/useFormStates.ts index 6903706..e61e8ce 100644 --- a/src/useFormStates.ts +++ b/src/useFormStates.ts @@ -109,7 +109,7 @@ export function useFormStates(opts: UseFormStatesOpts): UseFormS // If it didn't exist, then add to the cache. if (!form) { - form = createObjectState(config, initValue(config, map ? { map, input } : input), { + form = createObjectState(config, initValue(config, { map, input }), { maybeAutoSave: () => maybeAutoSave(form), }); if (addRules) { @@ -120,7 +120,7 @@ export function useFormStates(opts: UseFormStatesOpts): UseFormS // If the source of truth changed, then update the existing state and return it. if (existing && existing[1] !== input) { - (form as any as ObjectStateInternal).set(initValue(config, map ? { map, input } : input), { + (form as any as ObjectStateInternal).set(initValue(config, { map, input }), { refreshing: true, }); existing[1] = input; diff --git a/src/utils.ts b/src/utils.ts index 8081943..08176de 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -35,7 +35,7 @@ export function assertNever(x: never): never { throw new Error("Unexpected object: " + x); } -/** Introspects the `init` prop to see if has a `map` function/etc. and returns the form value. */ +/** Introspects the `init` prop to see if it has a `map` function/etc. and returns the form value. */ export function initValue(config: ObjectConfig, init: any): T { let value: any; if (isInput(init)) { @@ -47,6 +47,7 @@ export function initValue(config: ObjectConfig, init: any): T { } else { throw new Error("init must have an input or query key"); } + // Given our form config, pick out only the subset of fields out of `value` (unless it's a mobx class) return pickFields(config, value ?? {}) as T; }