Somename
Somename

Reputation: 3434

Show array elements in mapped array in ReactNative

My Reducer is :

Reducer:

const initialState = {
  1: {
     id: '1',
     name: 'Name1',
     number: 11,
     myArray:["P1tag1","P1tag2", "P1tag3"]
    },
  2: {
     id: '2',
     name: 'Name2',
     number: 22,
     myArray:["P2tag1","P2tag2", "P2tag3"]
    }
}

Used mapStateToProps and mapped newData. I'm rendering the data like this:

   const renData = Object.keys(this.props.newData).map((key, idx) => {
    let data = this.props.newData[key]
      return (
          <View>
            <Text>{data.name} </Text>

            <Text>{data.number} /Text>

            <Text>
              myArray // <= How do I show the items from myArray here? 
            </Text>
          </View>

      )
  })

data.name and data.number are displayed fine. I'm trying to figure out how to show the array myArray from data.

Thanks.

Upvotes: 0

Views: 71

Answers (1)

Hemerson Carlin
Hemerson Carlin

Reputation: 7424

Simply map through them:

<View> //or any other wrapper here
   {data.myArray.map((item, index) => <Text key={index}>{item}</Text>)}
<View>

Upvotes: 2

Related Questions