Skip to content
Discussion options

You must be logged in to vote

Yes, this is expected, and switching to useFormState / useController is the right fix.

formState is a Proxy. Reading a property on it (e.g. errors) is what subscribes to that slice of state. The proxy you get from useFormContext() is the same object useForm() returned in App:

// src/useForm.ts
_formControl.current.formState = React.useMemo(
  () => getProxyFormState(formState, control),
  [control, formState],
)

FormProvider just passes it down. So when TelField destructures formState: { errors } from the context, it's not creating a subscription for TelField. It's flipping the errors flag on the host's proxy. From then on, every error change re-renders App (the component that owns useForm)…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tony-hsueh
Comment options

Answer selected by tony-hsueh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants