fix: onSubmit should now behave as expected

* fix: memoize all non-function form props by default

* chore: migrate useStableFormOpts to useMemo

* fix: options passed to useField will not always cause a re-render

* chore: minor code cleanups

* test: add previously failing test to demonstrate fix

* chore: fix linting

* fix: running form.update repeatedly should not wipe form state

* test: add test to validate formapi update behavior

* test: add initial tests for useStableOptions

* chore: remove useStableOpts and useFormCallback
This commit is contained in:
Corbin Crutchley
2023-09-06 19:33:52 -07:00
committed by GitHub
parent 9424ed94f8
commit 6f76feee6b
11 changed files with 171 additions and 60 deletions

View File

@@ -17,13 +17,10 @@ function FieldInfo({ field }: { field: FieldApi<any, any> }) {
export default function App() {
const form = useForm({
// Memoize your default values to prevent re-renders
defaultValues: React.useMemo(
() => ({
firstName: "",
lastName: "",
}),
[],
),
defaultValues: {
firstName: "",
lastName: "",
},
onSubmit: async (values) => {
// Do something with form data
console.log(values);