Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use the useWatch from react-hook-form to get around the react-compiler memoization issues #376

Merged
merged 1 commit into from
Jun 22, 2024

Conversation

SeanCassiere
Copy link
Owner

The react-compiler doesn't play well with the form.watch API as it breaks the rules-of-react in an unobvious way, thus losing the reactivity that was intended. To get around this you need to wrap it in useMemo to trick the compiler. This change consumes the form.control in the provided useWatch hook by react-hook-form to maintain the reactivity of the original api without breaking the rules-of-react, thus letting the react-compilter work flawlessly without any hacks.

…eact-compiler memoization issues

the react-compiler doesn't play well with the `form.watch` api as it breaks the rules-of-react in an unobvious way, thus loosing the reactivity that was intended. to get around this you need to wrap it in `useMemo` to trick the compilter. this change consumes the `form.control` in the provided `useWatch` hook by `react-hook-form` to maintain the reactivity of the original api without breaking the rules-of-react, thus letting the react-compilter work flawlessly without any hacks.
@SeanCassiere SeanCassiere self-assigned this Jun 22, 2024
Copy link

vercel bot commented Jun 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rentall-clone ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 22, 2024 0:24am

@SeanCassiere SeanCassiere marked this pull request as ready for review June 22, 2024 12:24
@SeanCassiere SeanCassiere merged commit 021e149 into master Jun 22, 2024
3 checks passed
@SeanCassiere SeanCassiere deleted the fix-rhf-form-watch branch June 22, 2024 12:25
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.

1 participant