You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looking at my own React code and React code on Github, it seems like 95% of onChange handlers on inputs only ever use e.target.value. So a lot of code ends up looking doing something like: <input onChange={e => setUsername(e.target.value)} /> instead of simply <input onChange={setUsername} />.
It would make a lot of code more clean/readable if there was a prop that would directly pass e.target.value, e.g. <input onValue={setUsername} />.
Food for thought...
The text was updated successfully, but these errors were encountered:
There's no native equivalent for DOM input, but this is exactly what React Native's TextInput does. You can build your own custom component that does this for React DOM
@olalonde For what it's worth, in my opinion the native browser event argument makes more sense than just passing the value. Of course either approach may be abstracted into another, but with current api you can have a single handleChange handler and use it like this:
function handleChange(event) {
setState({ [event.target.name]: event.target.value });
}
Looking at my own React code and React code on Github, it seems like 95% of onChange handlers on inputs only ever use
e.target.value
. So a lot of code ends up looking doing something like:<input onChange={e => setUsername(e.target.value)} />
instead of simply<input onChange={setUsername} />
.It would make a lot of code more clean/readable if there was a prop that would directly pass
e.target.value
, e.g.<input onValue={setUsername} />
.Food for thought...
The text was updated successfully, but these errors were encountered: