Skip to content

🚄 perf: separate control context to prevent unnecessary rerenders#13234

Merged
bluebill1049 merged 2 commits intoreact-hook-form:masterfrom
newsiberian:separate-control-context
Jan 5, 2026
Merged

🚄 perf: separate control context to prevent unnecessary rerenders#13234
bluebill1049 merged 2 commits intoreact-hook-form:masterfrom
newsiberian:separate-control-context

Conversation

@newsiberian
Copy link
Contributor

@newsiberian newsiberian commented Jan 4, 2026

Introduce HookFormControlContext for internal hooks (useController, useFieldArray, useFormState, useWatch) to avoid rerenders when only control is needed.

Currently, even if the context were memoized, there would still be an unnecessary cause for rerenders in these hooks — formState — even though it's not actually used internally. This PR completely breaks the dependency on formState and makes the hooks isolated from the shared context.

I intentionally did not export the new hook in the public API, as I don't think there's a reason to expand it.

Partial work for #13233

@newsiberian newsiberian changed the title perf: separate control context to prevent unnecessary rerenders 🚄 perf: separate control context to prevent unnecessary rerenders Jan 4, 2026
Introduce HookFormControlContext for internal hooks (useController, useFieldArray, useFormState, useWatch) to avoid rerenders when only control is needed.
@newsiberian newsiberian force-pushed the separate-control-context branch from 4d29f85 to 2ac2426 Compare January 4, 2026 13:46
Copy link
Member

@bluebill1049 bluebill1049 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could u increase the bundle size config at the package.json? nice work

@bluebill1049 bluebill1049 merged commit 17c85ed into react-hook-form:master Jan 5, 2026
6 checks passed
@mattsputnikdigital
Copy link

Quick question about this change.

Previously I was passing in an additional function to the which I could get back from useFormContext(). This change breaks that. Would there be a way to still allow this?

@newsiberian
Copy link
Contributor Author

Quick question about this change.

Previously I was passing in an additional function to the which I could get back from useFormContext(). This change breaks that. Would there be a way to still allow this?

Could you consider using one more custom context for your function? You can create your own context as a one more wrapper around forms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants