-1

I'm using the map function to iterate through an array in the state. My code is:

theList(){

    return  this.state.lists.map((list) => {
            return(
                <View style={this.state.listStatus[list.id].status?styles.list:styles.list2}>
                    <Text>{list.name}</Text>
                </View>
            )
        })

    }   

How can I put the list.id in the this.state.listStatus[here]?

Somename
  • 3,376
  • 16
  • 42
  • 84
  • Does this answer your question? [Index inside map() function](https://stackoverflow.com/questions/38364400/index-inside-map-function) – Harun Yilmaz Dec 24 '19 at 17:01

1 Answers1

0

Assuming you have two arrays with the same index and size (lists and listStatus), you might need this.

The second parameter of the map function is the iteration index.

theList(){

    return  this.state.lists.map((list, listIndex) => {
            return(
                <View style={this.state.listStatus[listIndex].status?styles.list:styles.list2}>
                    <Text>{list.name}</Text>
                </View>
            )
        })

    }  
Ctznkane525
  • 7,297
  • 3
  • 16
  • 40