4 ms·
So with frameworks like React/Vue, every change to a field generates a request? Or are those handled locally in the shadow dom?
by djsumdog 9y ago
So with frameworks like React/Vue, every change to a field generates a request? Or are those handled locally in the shadow dom?
- xab9 9y agoTechnically yes. You can see it in the network panel.
- endless1234 9y agoNot at all. Sending off requests is a different thing entirely to controlled inputs, and you don't need a controlled input to do a request every keypress.
- xab9 9y agoDamn you're right. Thanks!
- mrtksn 9y agoThe pattern is to handle form fields locally in the browser as part of the application state. Basically, the value of the input is tied to a "state engine" that acts as a single source of truth and when the user types in the input you'll update the state so that the rest of the application can know what's going on in the form without accessing the DOM. The state engine is a fancy word for a variable that has a special setter function so that the changes can be reflected globally.
- baddox 9y agoCan’t speak about Vue, but that’s pretty much the recommended pattern for most input fields in React. But, as others have commented, it might be prudent to leave password inputs completely uncontrolled, i.e. let the browser do its normal thing for updating the DOM based on user input.
- mrtksn 9y agoUnfortunately, that’s very inconvenient with React because you’ll have to start thinking about dom elements lifecycle separately of the react app lifecycle.
- baddox 9y agoDefinitely. It’s going to be a struggle to implement things like password confirmation validation or a real-time password strength indicator.