felixakiragreen / react-kronos

A fast, intuitive, and elegant date and time picker for React.
https://felixakiragreen.github.io/react-kronos/
MIT License
90 stars 28 forks source link

Uncontrolled? #55

Open Noitidart opened 7 years ago

Noitidart commented 7 years ago

Is it really possible to do uncontrolled? In the demo it's connected to state. I need a totally uncontrolled field with just a defaultValue. In all cases I need defaultValue to be blank. Right now on re-render it is blanking out, or if I set a date prop it goes back to that original value.

felixakiragreen commented 7 years ago

You want the defaultValue to be null?

Noitidart commented 7 years ago

Thanks so much @dubert for the reply. Yes sir, it should be blank, and then when they pick something it should not change state, just set uncontrolled value of the input box via a ref or document.blah.value = 'rawr'. The important thing is, uncontrolled components do not get their uncontrolled value wiped out on re-render. When user clicks "submit" on my form I re-render my form to show a loading animation, at that point the Kronos field gets wiped out.

Basically I had expected an uncontrolled <Kronos defaultDate="blah"> should behave just like an uncontorlled <Input type="text" defaultValue="blah">.

felixakiragreen commented 7 years ago

Looks like you're correct. The uncontrolled is not truly uncontrolled. I'm not entirely sure how to implement this though, since there is a lot of internal logic handling the validation of the date and internal state storage. Do you have any recommendations?

I've read Facebook's page on uncontrolled components but it doesn't help me implement them.

Noitidart commented 7 years ago

Thanks @dubert!

I haven't looked into the internals yet :( I will try to take a peak