6 ms·
As users, don't you get mad when you type "mustang" in an input and it displays "msutgna" because of some badly handled onChange event? We are overriding so muc
by nkg 8y ago
As users, don't you get mad when you type "mustang" in an input and it displays "msutgna" because of some badly handled onChange event? We are overriding so much of the browser's default behavior that we need to reimplement its basic features.
- svachalek 8y agoYes. I wish native browser inputs would step out of 1994, but at the same time my preferred answer to this case is simply using an uncontrolled input rather than piling more layers of complexity on top of it.
- symboltoproc 8y agoI've never experienced that. Mind sharing an example?
- bestest 8y agoThat would happen when, for example, you're saving the value of the text input in redux, and the input is then updated with that value on change, although it's also updated by the user typing and the thread is blocked at the same time, thus we have a race condition. That said — it only happens when one over-engineers stuff. Make sure to have a single source of truth, and that will be avoided.
- deleted 8y ago[deleted]
- philipp-spiess 8y agoThe best approach is to always updated the input synchronously in React (in the same tick when the event is handled). If you do it in another tick, you will always have to handle race conditions. This is a problem for all input elements though, not specific to React or even the Web.
- nkg 8y agoThe last time I experienced it I was using search bar on AliExpress.com's mobile website
- reacweb 8y agoI have already encounter this behaviour, but I do not understand it. What is the mistake to avoid ?
- ex3ndr 8y agoThat probably not just input, but content editable. Unfortunately this feature is really very hard to support well and there are still bugs in all editors.