react-native-form-generator
react-native-form-generator copied to clipboard
make displayed values a controlled prop
Hi!
thanks for the lib! One question: I'm using InputField
and find it not ideal that the value
of the entered text is stored in the state of the component and it is therefore possible for it to drift away from the value that is in my state object.
More specifically: I have my state object that contains the value that the text field should display. Say I render the textfield with value={this.state.value}
(renders ok) then I change the value somewhere else which triggers a re-render. The InputField
will ignore this new value. What I can do is use the setValue
but I believe that goes against React.
So my question is - is it feasible to remove the value from state altogether (?), or alternatively implement componentWillReceiveProps? It doesn't seem difficult to get rid of it, looking at the code. This might apply to other components too.
edit: so I tried both (getting rid of it & componentWillReceiveProps) and they seem to work both with no problem.
I'm completely pro componentWillReceiveProps, because for some users is fundamental to set values in the fields programmatically. This behavior it's allowed in react and the internal state of the component is handled correctly. I'm going to do a new release with this and other changes. If you have any other suggestion I'm more than happy to help. Thank you.