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
Props.form and Effects Usage Problems #16599
Comments
Hello @raybooysen. Please provide a online reproduction by forking this link https://u.ant.design/codesandbox-repro or a minimal GitHub repository. Issues labeled by 你好 @raybooysen, 我们需要你提供一个在线的重现实例以便于我们帮你排查问题。你可以通过点击 此处 创建一个 codesandbox 或者提供一个最小化的 GitHub 仓库。7 天内未跟进的 issue 将会被自动关闭。 |
This issue is closed because it has been marked as |
I am also running into this issue. I created codesandbox reproduces this issue. Please see comment in |
I have a similar issue just with updating the form fields if the initial props changes https://codesandbox.io/s/antd-form-missing-in-effect-dependencies-z44s0 |
This may try to fix it in 4.0. |
So one solution I found is to useRef, example: const savedForm = useRef()
useEffect(() => {
savedForm.current = form
})
useEffect(() => {
savedForm.current.resetFields()
}, [name]) |
Always create a new form object. https://github.com/react-component/form/blob/master/src/createForm.js |
It is best that the |
@PaulPCIO I will try your solution to see if it works for me. Thanks for sharing! |
Reproduction link
N/A
Steps to reproduce
Create a functional react component that is wrapped in a Form.create()
In that functional component, use the useEffect hook to validate fields
What is expected?
Unsure, I'm looking for guidance here. Because we're using props.form to validate the fields, the React guidance is to pass in props.form into the dependency array.
However, on each validate call, the props.form object is recreated, which causes an infinite loop of renders.
What is actually happening?
We hit an infinite scheduled loop of re-rendering, re-validation because the hook determines that props.form has changed.
The text was updated successfully, but these errors were encountered: