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

fix: stabilize useField public handler identity #931

Conversation

kapral18
Copy link
Contributor

@kapral18 kapral18 commented Jul 21, 2021

useField public handlers like onFocus, onChange, onBlur are changing their identities based on various internal variables and externally available props/(config parts) like value, name, parse etc...

I am suggesting that public handlers should not be subject to identity change at all, so that consumers can rely on those without jumping through hoops with useRef as in https://reactjs.org/docs/hooks-faq.html#what-can-i-do-if-my-effect-dependencies-change-too-often.

As a consequence after this change consumer code relying on this behavior might break, hence this is a BREAKING CHANGE

Closes #816

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 21, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 057c7a2:

Sandbox Source
🏁 React Final Form - Third Party Components Example Issue #816

@kapral18 kapral18 force-pushed the fix/stabilize-usefield-public-handler-identities branch from 210024b to f5d7212 Compare July 21, 2021 13:17
BREAKING:
onBlur, onChange, onFocus handlers no longer change identity
if props or internal state is changed,
thus on consumer side the behavior relying on handler identity can break

Closes final-form#816
@kapral18 kapral18 force-pushed the fix/stabilize-usefield-public-handler-identities branch from f5d7212 to 057c7a2 Compare July 21, 2021 13:38
@erikras erikras merged commit b634ace into final-form:main Jul 22, 2021
@erikras
Copy link
Member

erikras commented Sep 29, 2021

Published in v6.5.4.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

input.onChange has a new reference each time value changes
2 participants