首页 > 解决方案 > 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})}}
        />

        ))
        }

标签: reactjsreact-native

解决方案


您可以使用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>
     ))
   }

或者

{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})}}
        />
      </>
     ))
   }

我认为这种方式更清洁


推荐阅读