0

I want to use react-native-flexi-radio-button in my project to select one of the item in list form array and use this code

 {this.state.Rooms.map(function (value,index) {

                    console.log(value.id)

                    return(
                        <RadioGroup  onSelect ={(index, value) => this.onSelect(index, value)}>
                            <RadioButton value={value.id} isSelected={false} index={index}>
                                {/*<Text>{i.title}</Text>*/}
                            </RadioButton>
                        </RadioGroup>
                    )

                })

                }

but when i click on any button, it returns _this3.onselect is not function and its this function

  onSelect=(index,value)=>{
      console.log(index,value)
    }

how to solve this?

Ray
  • 9,184
  • 3
  • 27
  • 44
Mohamad reza1987
  • 193
  • 1
  • 7
  • 28

1 Answers1

0

Change this part of the code

 {this.state.Rooms.map(function (value,index) {

to:

{this.state.Rooms.map((value,index) => {

Refer to this thread to know the difference between arrow functions vs the usual function declaration

Ray
  • 9,184
  • 3
  • 27
  • 44