issue: useController’s fieldState.isValidating breaks the on-demand re-render mechanism, causing performance issues. #13501
Version Number7.65.0 Codesandbox/Expo snackhttps://codesandbox.io/p/devbox/winter-cookies-d5w5d6 Steps to reproduce const {
field,
fieldState: { error, isValidating }, // remove isValidating will increase performance
} = useController({
name: "name",
control,
rules: {
validate: (value) => {
console.log("validate name");
return value.trim() !== "" || "Name is required";
},
},
});When I try to read fieldState.isValidating, any field’s onChange will trigger all fields to re-render once. This can cause performance issues when there are a large number of fields. 2025-10-31.11.43.53.movExpected behaviourtrigger render once What browsers are you seeing the problem on?No response Relevant log outputCode of Conduct
|
Replies: 1 comment
|
I looked into this a bit — this behavior is actually expected. The key thing to understand is that When you do: fieldState: { error, isValidating }you're indirectly subscribing to Why all fields re-renderIn react-hook-form, anything you read from formState creates a subscription. So if multiple fields read isValidating:
That’s why removing isValidating improves performance. What I’d suggest
const {
formState: { isValidating }
} = useForm();{isValidating && <p>Validating...</p>}
const [loading, setLoading] = useState(false);
const { field } = useController({
name: "name",
control,
rules: {
validate: async (value) => {
setLoading(true);
await new Promise((r) => setTimeout(r, 500));
setLoading(false);
return value.trim() !== "" || "Name is required";
},
},
});{loading && <span>Checking...</span>} |
I looked into this a bit — this behavior is actually expected.
The key thing to understand is that
isValidatingis not field-level.When you do:
you're indirectly subscribing to
formState.isValidating, which is shared across the entire form.Why all fields re-render
In react-hook-form, anything you read from formState creates a subscription.
So if multiple fields read isValidating:
That’s why removing isValidating improves performance.
What I’d suggest
Don’t use isValidating inside fields (most cases). This keeps each field isolated and only re-renders when it actua…