From abba0ddf21df688c8624270baf7d4cf1de0980dc Mon Sep 17 00:00:00 2001 From: GabrielModog Date: Wed, 30 Aug 2023 13:52:55 -0300 Subject: [PATCH 1/3] fix: cannot update a component/bad setState --- packages/react-form/src/useForm.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/react-form/src/useForm.tsx b/packages/react-form/src/useForm.tsx index a145013c9..d983df6e4 100644 --- a/packages/react-form/src/useForm.tsx +++ b/packages/react-form/src/useForm.tsx @@ -2,7 +2,7 @@ import type { FormState, FormOptions } from '@tanstack/form-core' import { FormApi, functionalUpdate } from '@tanstack/form-core' import type { NoInfer } from '@tanstack/react-store' import { useStore } from '@tanstack/react-store' -import React from 'react' +import React, { useEffect } from 'react' import { type UseField, type FieldComponent, Field, useField } from './useField' import { formContext } from './formContext' @@ -75,7 +75,10 @@ export function useForm(opts?: FormOptions): FormApi { }) formApi.useStore((state) => state.isSubmitting) - formApi.update(opts) + + useEffect(() => { + formApi.update(opts) + }, []) return formApi as any } From b17e9836d4df1dccde92f45e37c041328989c516 Mon Sep 17 00:00:00 2001 From: GabrielModog Date: Thu, 31 Aug 2023 17:10:08 -0300 Subject: [PATCH 2/3] fix: add dep useEffect in useForm --- packages/react-form/src/useForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-form/src/useForm.tsx b/packages/react-form/src/useForm.tsx index d983df6e4..685759963 100644 --- a/packages/react-form/src/useForm.tsx +++ b/packages/react-form/src/useForm.tsx @@ -78,7 +78,7 @@ export function useForm(opts?: FormOptions): FormApi { useEffect(() => { formApi.update(opts) - }, []) + }, [opts]) return formApi as any } From ea1ab1a15ac15be2eda8206937f078d66e786869 Mon Sep 17 00:00:00 2001 From: GabrielModog Date: Thu, 31 Aug 2023 17:33:03 -0300 Subject: [PATCH 3/3] fix: add missing deps in useForm --- packages/react-form/src/useForm.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-form/src/useForm.tsx b/packages/react-form/src/useForm.tsx index 685759963..607392ac3 100644 --- a/packages/react-form/src/useForm.tsx +++ b/packages/react-form/src/useForm.tsx @@ -2,7 +2,7 @@ import type { FormState, FormOptions } from '@tanstack/form-core' import { FormApi, functionalUpdate } from '@tanstack/form-core' import type { NoInfer } from '@tanstack/react-store' import { useStore } from '@tanstack/react-store' -import React, { useEffect } from 'react' +import React from 'react' import { type UseField, type FieldComponent, Field, useField } from './useField' import { formContext } from './formContext' @@ -76,9 +76,9 @@ export function useForm(opts?: FormOptions): FormApi { formApi.useStore((state) => state.isSubmitting) - useEffect(() => { + React.useEffect(() => { formApi.update(opts) - }, [opts]) + }, [formApi, opts]) return formApi as any }