0

I'm trying to print an Array whose name is being calculated based on selected value. e.g.

const ANotes = ["B", "C", "D"];
const keyNotes = MyNotes[selected] + "Notes"; //value is ANotes

Trying to render it as:

<View>
        {{keyNotes}.map((item, key)=>(
         <Text key={key} 
          //style={styles.TextStyle} 
          //onPress={ this.SampleFunction.bind(this, item) }
          > { item } , </Text>)
        )}
      </View>

When I try to render it in View in my Component it gives error. I'm new to React Native so not able to figure this one. I want the output to show B, C, D in the App.

It gives error: TypeError: undefined is not a function.

pulkitgulati
  • 41
  • 2
  • 9

1 Answers1

0

You cant use a string value to access a variable in the local scope without it being attached to some object or array check out this SO for some solutions

Seems you're using functional component if you switch to a class component you can then access it with this[keyNotes]

<View>
     {this[keyNotes].map((item)=><Text key={item}> {item}Notes,  </Text>)} 
</View>

Here's a working sandbox (I'm using react not react-native so I changed to dom eelments)

Moshe Sommers
  • 1,466
  • 7
  • 11