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

Not possible to create controlled component with nil value #73

Open
lucywang000 opened this issue Sep 2, 2020 · 1 comment
Open

Not possible to create controlled component with nil value #73

lucywang000 opened this issue Sep 2, 2020 · 1 comment

Comments

@lucywang000
Copy link
Contributor

lucywang000 commented Sep 2, 2020

After this commit, when the :value prop is nil, helix would replace it with undefined. But in react components like input etc. with :value nil is treated as a controlled component, while :value undefined is treated as uncontrolled.

This is a problem e.g. when using the Autocomplete component of material-ui, the :value prop must be either nil or one of the values in the options list. However when I try to give it a nil, helix changes it to undefined, which effectively make this component a uncontrolled one. Later when the user chooses a value from the auto complete list, the component would become a controlled element and cause errors.

screenshot

@lilactown
Copy link
Owner

Hmm. To add more context, I don't believe that nil is a valid :value for most DOM elements, hence the reason that we would prefer to coerce nil to js/undefined when used with DOM elements.

Clearly, this is too prescriptive in the general case of working with 3rd party components (or native components of other reconcilers). I'll have to think about the best way to solve this; my hunch is that we should distinguish between transforms necessary for "native" elements, and transforms necessary for DOM elements.

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