0

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.

1

1 Answer 1

2

Simply map through them:

<View> //or any other wrapper here
   {data.myArray.map((item, index) => <Text key={index}>{item}</Text>)}
<View>
Sign up to request clarification or add additional context in comments.

2 Comments

Cannot find variable: index Tried in a Text tag and outside it .. same error.
That's not possible. index is the respective item's index in myArray.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.