Answer the question
In order to leave comments, you need to log in
React. How to store number type in option value?
...
<select name="field" value={1} onChange={this.changeForm}>
<option key={0} value={1}>1</option>
<option key={1} value={2}>2</option>
</select>
...
Answer the question
In order to leave comments, you need to log in
No way. In attributes, all values are stored as strings.
Therefore, I would advise keeping different handlers for different data types in the input. Well or there on isNaN of check to do.
...
const number = isNaN(+value) ? value : +value;
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question