react-kronos icon indicating copy to clipboard operation
react-kronos copied to clipboard

Uncontrolled?

Open Noitidart opened this issue 7 years ago • 4 comments

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.

Noitidart avatar Mar 12 '17 04:03 Noitidart

You want the defaultValue to be null?

felixakiragreen avatar Mar 13 '17 14:03 felixakiragreen

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">.

Noitidart avatar Mar 13 '17 20:03 Noitidart

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.

felixakiragreen avatar Mar 14 '17 14:03 felixakiragreen

Thanks @dubert!

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

Noitidart avatar Mar 14 '17 17:03 Noitidart