Reputation: 301
I'm trying to map an array and reference the .map()
parameters 'button
' and 'i
', in my React Native JSX. Feel like I've tried everything at this point. How do I correctly reference button
and i
as an item in my styles
object within a JSX style prop? is this not possible?
{buttonSet.map(function(button, i) {
let pleaseHelpMe = button + `${i}`;
return (
<TouchableHighlight
style={[styles.abacusButton, styles.pleaseHelpMe]}
...
>
<Text>X</Text>
</TouchableHighlight>
);
})}
Upvotes: 0
Views: 131
Reputation: 37775
You need to use []
notation when you want to access property using variable,
{buttonSet.map(function(button, i) {
let pleaseHelpMe = button + `${i}`;
return (
<TouchableHighlight
style={[styles.abacusButton, styles[pleaseHelpMe]]}
...
>
<Text>X</Text>
</TouchableHighlight>
);
})}
Upvotes: 1