Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display input value from state

I am looking to set the value of input from state however not successful.

Here is my attempt

state={
    value: ["one","two","three"]
}

render (
    return(
    {
        this.state.value.map(val=>{
          return <Input type="radio" value={val} />
        })
    })
)

the result I am getting is only one input element without the value displayed. as

* 

What I am looking for is for three input element with there value displayed as

* One
* two
* Three

1 Answers

Change your render like follwong.

render() {
    return (
        this.state.value.map(function(val) {
            return <div> <input type = "radio" value = {val}/>{val}</div>
        })
    )
  }

Online Demo

Note: If you want that you will be able to select only one radio button, in that case you need to group the radio button together by giving a common name.

like image 53
PSK Avatar answered Aug 08 '26 15:08

PSK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!