react-native-form-generator icon indicating copy to clipboard operation
react-native-form-generator copied to clipboard

make displayed values a controlled prop

Open vonovak opened this issue 8 years ago • 1 comments

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.

vonovak avatar Aug 23 '16 18:08 vonovak

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.

MichaelCereda avatar Aug 23 '16 20:08 MichaelCereda