novous0000
novous0000

Reputation: 29

How can I use two component with map in react-native

I want to use two component Text and Radiobutton with map. Like this..

please help me!

{Object.keys(temp_data).map(room => (
       <Text> {room} </Text>

        <RadioForm
         radio_props={radio_props}
         initial={0}
         buttonColor={'#2196f3'}
         animation={true}
         onPress={(value) => {this.setState({value:value})}}
        />

        ))
        }

Upvotes: 0

Views: 46

Answers (2)

ridvanaltun
ridvanaltun

Reputation: 3020

You can use fragment

{Object.keys(temp_data).map(room => (
       <React.Fragment>
         <Text> {room} </Text>
         <RadioForm
         radio_props={radio_props}
         initial={0}
         buttonColor={'#2196f3'}
         animation={true}
         onPress={(value) => {this.setState({value:value})}}
        />
      </React.Fragment>
     ))
   }

or

{Object.keys(temp_data).map(room => (
       <>
         <Text> {room} </Text>
         <RadioForm
         radio_props={radio_props}
         initial={0}
         buttonColor={'#2196f3'}
         animation={true}
         onPress={(value) => {this.setState({value:value})}}
        />
      </>
     ))
   }

I think this way more cleaner

Upvotes: 1

giotskhada
giotskhada

Reputation: 2452

Just wrap them in a View

{Object.keys(temp_data).map(room => (
       <View>
         <Text> {room} </Text>
         <RadioForm
         radio_props={radio_props}
         initial={0}
         buttonColor={'#2196f3'}
         animation={true}
         onPress={(value) => {this.setState({value:value})}}
        />
      </View>
     ))
   }

Upvotes: 0

Related Questions