Replies: 7 comments 6 replies
|
I've attempted to turn on the React Compiler this week, and yeah, there are definitely issues. So far I've definitely ran into the well-known issues with As far as I can see Anyways, it would be really great with some guidance and a migration guide of some sort here. We have for example a bunch of cases like |
|
I have problems when using |
|
Any updates regarding React Compiler support? |
|
For anyone here who needs it, you can disable React Compiler granularly using the I wrap my forms in a special hook usually, and placing the directive in the hook function body fixes the issue for me: import { type UseFormProps, useForm } from 'react-hook-form';
function useFormCompat(props?: UseFormProps) {
// Disable react compiler until react-hook-form supports it.
// https://github.com/orgs/react-hook-form/discussions/12524
'use no memo';
return useForm(props);
}
export function Component() {
const form = useFormCompat();
return <>...</>
} |
|
This should answer the 2nd bullet of OP's question. I wanted to get a fuller picture of what RHF apis were broken, and of those, which had valid alternatives (e.g. watch -> useWatch). Made this repo that tests all the apis and wrote up a report of the results. https://github.com/timkindberg/rhf-compiler-compat TLDR; Here are the key take-aways for devs wondering what they need to do for now until this is fixed in the library: WorkaroundsFor each breaking API, here are the recommended workarounds:
|
|
For production code today, I would treat React Compiler + RHF as an opt-in migration, not a blanket switch. The safe mental model is:
So this pattern is compiler-friendlier: const type = useWatch({ control: form.control, name: 'type' })
return type === 'company' ? <CompanyFields /> : <PersonFields />than this: return form.watch('type') === 'company' ? <CompanyFields /> : <PersonFields />For large apps, I would migrate in layers:
That gives you a path to use the compiler around forms without betting the whole form system on compiler compatibility at once. |
|
I tested this with react-hook-form 7.89.0, React 19.2 and babel-plugin-react-compiler 1.0.0. Two things still break for me:
Both components compile fine, and the eslint compiler rules don't show any warning. Using useWatch fixed both. I shared a related test here: Linkedin Post |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
Is it's safe to use today the react-hook-form library together with the react compiler ?
I saw already some recommendations to use useWatch instead of watch function, but there also seem to be issues with other functions as well, for example the getValues function.
All reactions