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

useField pass a validate function will cause Infinite loops #44

Closed
chenjigeng opened this issue May 3, 2019 · 4 comments · Fixed by #46
Closed

useField pass a validate function will cause Infinite loops #44

chenjigeng opened this issue May 3, 2019 · 4 comments · Fixed by #46

Comments

@chenjigeng
Copy link

chenjigeng commented May 3, 2019

Are you submitting a bug report or a feature request?

bug report

Sandbox Link

https://codesandbox.io/s/m38k650n79

See the console.

Other information

I see the source code of useField and find the reason.
image
In react function, every render will product new validate function.So it will cause this problem. Although we can use useCallback to avoid it.But it's so hard to use for user.Can we use useCallback in the inner or something else to solve this.

@chenjigeng
Copy link
Author

Find another solution: Put the validate function declaration outside the render function.But if someone doesn't know the internal implementation of useField, they might make the same mistake as me

@apanizo
Copy link
Contributor

apanizo commented May 10, 2019

@chenjigeng thanks for reporting it. I created the PR including validation at field level. Today we have discovered the bug ourselves iov-one/ponferrada#160

I do not have too much free time these days, I will take a look and fix it as soon as I can.

Thanks!

christophehurpeau added a commit to christophehurpeau/react-final-form-hooks that referenced this issue May 20, 2019
@apanizo
Copy link
Contributor

apanizo commented May 31, 2019

@chenjigeng ☝️ ☝️ ☝️

erikras pushed a commit that referenced this issue Jul 12, 2019
* fix: validator infinite loops

fixes #44

* test: update useField test
@erikras
Copy link
Member

erikras commented Jul 12, 2019

Published fix in v2.0.1.

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 a pull request may close this issue.

3 participants