React Native pass parameters through map function React Native pass parameters through map function reactjs reactjs

React Native pass parameters through map function


In both cases you are unnecessarily wrapping item in {}. For both of these lines, the expressions inside the outer {} are pure javascript (an array and a function) and should follow javascript syntax.

So the lines should read as follows:

style={[styles.button, (this.state.location===item && styles.buttonPressed)]}

and

onPress={()=>this.buttonPress(item)}


You should store this in another variable : let _this =this;

Then use _this instead of this


the issue is happened because you are using function(item, key){ and you have to use arrow function

let locations = this.state.campus.map((item, key) => { return <TouchableHighlight key={key}..   

you have to do it for keep using 'this' context