HTML Input ValueAs

Tobias Zimmermann1 minute reading time

Who would have thought it, but there is an alternative to parseInt and parseFloat to work with user input.

tsx
<input type="number" onChange={(event) => {
console.log(event.target.valueAsNumber)
}} />

As if that's not enough Good News, there's also valueAsDate:

tsx
<input type="date" onChange={(event) => {
console.log(event.target.valueAsDate)
}} />

More info can be found on the Builder.io Blog.