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

[@mantine/form] use-form: Make functions referentially stable #1383

Merged
merged 3 commits into from
May 8, 2022

Conversation

mattrunyon
Copy link
Contributor

Fixes #1196, #1193

This makes all functions returned by useForm stable. I used the eslint react-hooks plugin for their exhaustive dependencies rule while converting these. It helped catch everywhere that the state needed to be switched to using the ref value within the useCallback uses

Copy link
Member

@rtivital rtivital left a comment

Choose a reason for hiding this comment

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

I haven't checked how it works, but if tests are passing, then it is 👍

@mattrunyon
Copy link
Contributor Author

Made the changes you suggested (and also made another helper hook to track the state of a prop in a ref).

I also added a unit test for checking the functions are stable. Tested it failed when I removed useCallback from one of functions returned by the hook

@mattrunyon mattrunyon requested a review from rtivital May 7, 2022 06:24
@rtivital rtivital merged commit adb476c into mantinedev:master May 8, 2022
@rtivital
Copy link
Member

rtivital commented May 8, 2022

Thanks!

rtivital added a commit that referenced this pull request May 8, 2022
@rtivital
Copy link
Member

rtivital commented May 8, 2022

I've merged it without checking how it works in real demos (stupid of me) and it turns out that it does not work at all – all demos in broken (values updates are random). I've reverted the changes, so if you want, you can open another PR for this.

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.

Excessive re-rendering from useForm hook
2 participants