Skip to content

Commit e5ed818

Browse files
committed
feat(useForm): add reactive getters for form data
Introduce reactive getters for all form data properties in the useForm hook. This allows consumers to access form fields reactively, improving reactivity and consistency in Svelte components.
1 parent 664c038 commit e5ed818

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/svelte5/src/useForm.svelte.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,16 @@ export default function useForm<TForm extends FormDataType<TForm>>(
103103
}
104104
}
105105

106+
// Create reactive getters for all form data properties
107+
const formDataGetters = Object.keys(initialData).reduce((carry, key) => {
108+
return {
109+
...carry,
110+
get [key]() { return get(formData, key) }
111+
}
112+
}, {} as TForm)
113+
106114
const form: InertiaFormRunes<TForm> = {
107-
...formData,
115+
...formDataGetters,
108116
get isDirty() { return isDirty },
109117
get errors() { return errors },
110118
get hasErrors() { return hasErrors },

0 commit comments

Comments
 (0)