Select initialValue not getting updated on re-render #907
-
Scope: Form Renderer Description Everything works fine but the initial value is not updated once the data is available. Is there something I am missing? Following is the code:-
In the above if I remove the
Schema <If it's possible, please provide a schema which reproduces the issue> |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@jinxac initial value is only ever set on the first component render. Meaning that if you change it, the consuming component won't be affected. Here is roughly the flow: // before first render
{
input: {
value: undefined
},
meta: {
initial: 'foo'
}
}
// during field initialization initial value gest copied to value
{
input: {
value: 'foo'
},
meta: {
initial: 'foo'
}
}
// initial value change after render
{
input: {
value: 'foo'
},
meta: {
initial: 'new initial value'
}
} The value has a higher priority than the initial value so it will ignore the new initial value. To achieve this change, I would suggest adding an effect to your component and monitor the field If you want to access the field state outside of the field, just call |
Beta Was this translation helpful? Give feedback.
-
Hey @jinxac , I think you can make a simple workaround to reinitialize
This should ensure that the select will be re-mounted.
This ensures that the |
Beta Was this translation helpful? Give feedback.
Hey @jinxac , I think you can make a simple workaround to reinitialize
initialValue
each time options are changed:key
on the select (i.e. increase number by one)This should ensure that the select will be re-mounted.
initializeOnMount = true
This ensures that the
initialValue
will be updated when the component is mounted.