-
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
The new React lifecycle methods - breaking change #3953
Comments
@magaton Odd. I would have expected that the constructor for |
No, the form does not see the change if the state is changed in the custom widget during the initial render. The app is using the latest 5.14.2 and is not working properly. The same is with all versions since 5.13.3. There is also a README summary about my observations and the screenshot of how it looks with version 5.13.2 (before lifecycle methods change). If you change @rjsf version to 5.13.2 you will be able to verify this Thanks again for looking into this. |
@magaton in both widget components, instead of modifying formData directly and then doing a shallow copy ({ ...formData }), it is recommended to create a completely new state object. This ensures that React detects the state change and re-renders the component. In all places code snippet:
replace with code:
It worked for me. |
@lrozewicz Thanks very much for the reply. It took me basically a whole week to test it. There is definitely a different behavior noticed in both
instead of:
TBH, although I understand what you are saying, the last step I am doing is that I call
which should recreate the object and make the change noticed in @rjsf library. Some of the behaviours are quite odd, like that:
I feel I cannot find my way through since there is not a single:
Then there is a question of defaults, how they are initially populated in
@heath-freenome I am now questioning whether there is something in my custom widgets that is causing this malfunction. Is there an example (sample project) that would demonstrate the following concepts I am employing in my project, probably in the wrong way
Thanks, |
@magaton WOW, you are really bending the heck out of the rjsf code base. I'm curious why you aren't doing most of this work inside of |
I wish I knew myself :) but, this is the 1st React code I have seen in my life :) I was always on the other side :) |
Prerequisites
What theme are you using?
mui
Is your feature request related to a problem? Please describe.
Up until version 5.13.2 our app, based on rjsf (mui) was working well. Exceptions are the issues I have already filed:
But with version 5.13.3 in Form.tsx
UNSAFE_componentWillReceiveProps
was replaced with:componentDidUpdate
andgetSnapshotBeforeUpdate
.Here is the gist of the problem. We have 3 screen admin UI, each with its own schema and UI schema. We also have a couple of custom select widgets that take a value from formData, do some calculations, and update the state (formData) with the result array.
The issue happens on the initial render of, e.g. 2nd screen, where based on the formData from the 1st screen we need to set defaults (update formData). With
UNSAFE_componentWillReceiveProps
, it was working well, namely when our custom selects fired, the change was detected inUNSAFE_componentWillReceiveProps
and the screen was re-rendered, but now,componentDidUpdate
is not called on the initial render (as described in jsdocs and react docs).I understand that the main use case supported by the current design is to change state based on
onChange
property in the<Form>
, but in our case (initial render), there is noonChange
event. We read passed formData in the custom widget, do the calculation, and update the state that is then used for conditional schemas on the 2nd screen.What would be the recommended way to force re-render in our custom select widget, now that there is no
UNSAFE_componentWillReceiveProps
?We feel stuck :(
I filed this issue as a feature since it is related to our multi-form scenario with custom widgets, so not really a common use case. Sorry, if not appropriate.
Thanks very much in advance!
Describe the solution you'd like
Any idea/workaround/feature-switch that would allow re-rendering from our custom widgets.
Describe alternatives you've considered
We are not a react shop, so most of our investigation was chasing our own tail. We have tried:
getDerivedState
, no luckuseRef
- it does help when our custom select works with the previous formData, but we also have a custom select that needs both previous formData and specific fields on the 2nd form filled (so it is not just initial render, that we need to handle).The text was updated successfully, but these errors were encountered: