react-component / form

React High Order Form Component(web & react-native)
http://react-component.github.io/form/
MIT License
1.81k stars 296 forks source link

React 16.3 warning #171

Open super918180 opened 6 years ago

super918180 commented 6 years ago

I use rc-ffrm in React 16.3, and get warning as this: A component is changing an uncontrolled input of type undefined to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://fb.me/react-controlled-components

yesmeck commented 6 years ago

Could you reproduce your issue on https://codesandebox.io?

marklawlor commented 6 years ago

Reproduced with the demo in the README.md

https://codesandbox.io/s/xzj4npj4k4

Official demos have the same issue

http://react-component.github.io/form/examples/across-router.html#/

Just enter a value into an input and the warning appears

benjycui commented 6 years ago

Just set initialValue for the input.

marklawlor commented 6 years ago

But I'd like the value in the form to an have undefined value, as the field is optional

For my use case I have a number field that is optional, but if the user selects a value it must be >0. If I set the initialValue to undefined I get the same error, and if I set it to "" (which the react warnings say you should if you want it to be empty) the number field's value is a string.