Skip to content

Watch subscriber for errors/touchedFields/... objects #10895

Answered by Moshyfawn
yishay-at-bay asked this question in Ideas
Discussion options

You must be logged in to vote

Ah, I see! Sorry, I was focused on the "re-renders" part and the useEffect part has slipped my mind 🫣

The behavior you're seeing is a "side-effect" of the formState performance optimization; it's wrapped in a Proxy object to make sure the updates are run only for the states that you're subscribed to. You can read more about it in the formState rules section of RHF docs.

formState is updated in batch. If you want to subscribe to formState via useEffect, make sure that you place the entire formState in the optional array.

You want to set formState as your useEffect array dependency and access the form state props you're interested in inside the setup code.

const { formState } = useForm()

u…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@yishay-at-bay
Comment options

@Moshyfawn
Comment options

Answer selected by yishay-at-bay
@yishay-at-bay
Comment options

@Moshyfawn
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants