lilactown / helix

A simple, easy to use library for React development in ClojureScript.
Eclipse Public License 2.0
627 stars 52 forks source link

Not possible to create controlled component with nil value #73

Open lucywang000 opened 4 years ago

lucywang000 commented 4 years ago

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 commented 4 years ago

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.