-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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.onChange
ignored if i update other state in the parent component from a custom widget
#3914
Comments
@linde12 The |
Hey. Thanks for taking the time. I get that we only get a subset of the formData object and that we can only make changes to that subset using the onChange callback. What i dont get is why also calling my own callback, which updates state in the parent (the same component that renders Form), would prevent this from working. Do you understand what i mean? Like, why is my setFile call making props.onChange stop working, but if i remove that call or do it within flushSync/setTimeout (schedule it after a rerender) it works. |
@nickgros If i instead call So, to clarify:
|
Also: not using controlled Form (setting formData and passing onChange) also causes the entire form to be emptied completely if a parent state change happens in one of the widget callbacks. Did not look into if its even possible to work around this. I believe, in the end, that these issues boil down to using |
Here is just a proof of concept implementation i made with expected behavior https://codesandbox.io/s/compassionate-heyrovsky-dsr62z?file=/src/App.js Here I don't derive any state but instead I have a variable which either points to So if the component is uncontrolled (no values/formData passed to the component), we use internal state. You can remove |
@linde12 Is this still a problem since the replacement of the |
Prerequisites
What theme are you using?
core
Version
4.x, 5.x
Current Behavior
I have to use
flushSync
orsetTimeout
to flush my state changes in my custom widgets before callingprops.onChange
Expected Behavior
I should not have to call
flushSync
but simply update my state and then callprops.onChange(value)
in my custom file upload widget.Steps To Reproduce
formData
andfile
are printed periodicallyformData
contains a file path (fakepath) andfile
is a reference to aFile
flushSync
line and uncomment the the line that doessetFile(file)
without flushSyncfile
is set,formData
is empty - it is as if the change was never received.Environment
No response
Anything else?
I am genuinely curious to why this is happening. I set up something similar without rjsf (where a child component would call 2 callbacks that both update the parent state) and there was no issue.
The text was updated successfully, but these errors were encountered: