Skip to content
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

make displayed values a controlled prop #53

Open
vonovak opened this issue Aug 23, 2016 · 1 comment
Open

make displayed values a controlled prop #53

vonovak opened this issue Aug 23, 2016 · 1 comment

Comments

@vonovak
Copy link

vonovak commented Aug 23, 2016

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 vonovak changed the title [InputField] make value a controlled prop make values a controlled prop Aug 23, 2016
@vonovak vonovak changed the title make values a controlled prop make displayed values a controlled prop Aug 23, 2016
@MichaelCereda
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants