3 ms·
Part of the point (from a React perspective) is that everything in a React UI is driven by the data - so your data (state) should always control the UI. If you
by chrisa 7y ago
Part of the point (from a React perspective) is that everything in a React UI is driven by the data - so your data (state) should always control the UI.
If you store some state in JS variables, and some in the DOM (forms), then that's not true anymore. That's not necessarily a problem if you're expecting it (uncontrolled components are a valid React paradigm) - but if you're expecting controlled components, but some of them aren't, then you can run into trouble.
Also, once you're used to controlled components, it actually feels like a hassle to keep the data in the DOM - you have to constantly be getting it from the DOM to do form validation, submitting, field resetting, etc.
Again - I would say that neither is more right or wrong; but it's more of a style choice.
- bluebill1049 7y agoThis is a really good reply! In fact, React hook form is based on uncontrolled components, I guess the mainstream is still controlled, but I would like to give some fo the love to uncontrolled and explore the benefits from it.