What is the correct way to use boolean data in switches. Values will be converted from boolean strings to strings if they are used directly.
JSON data for preloaded input fields:
var question = [
{value: true, name: "Yes"},
{value: false, name: "Not this time"}
]
Switch Fields:
<input type="radio"
name="question"
onChange={this.state.onRadioChange}
value={this.state.question[0].value} /> {this.state.question[0].name}
<input type="radio"
name="question"
onChange={this.state.onRadioChange}
value={this.state.question[1].value} /> {this.state.question[1].name}
Binding for onRadioChange:
onRadioChange: function(e) {
console.log(e.target.value);
}
The console log shows that the selected values are converted from boolean strings to strings.
onRadioChange "true"/"false" booleans e.target.value, . , "e.target.checked" , , booleans ( ).
, REST.
- ReactJS? , .