JMcFar
JMcFar

Reputation: 301

Bracket syntax problem in React Native -- possibly only a JavaScript syntax issue

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

Answers (1)

Code Maniac
Code Maniac

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

Related Questions