0

On optn we have following data

"optn": [
    "ഫത്തേപ്പൂര്  സിക്രി",
    "ഖജൂരാഹോ ക്ഷേത്രം",
    "ചാര്മിനാര്",
    "കുത്തബ്മീനാര്"
],

iteration done as below,but while calling example[0] getting only first letter like "ഫ", "ഖ", "ച", "ക" on 'example' only getting error

Invariant Violation:Objects are not valid as a react child(found: object with keys{key,index}) if you meant to render a collection of children use an array instead

objAns= this.state.optn.map((example,index) =>{
  return(
    <View  key={index.toString()} >
    <RadioButton currentValue={this.state.value} value={index+1} onPress={this.handleOnPress.bind(this)}>
    <Text>{example[0]}</Text>
    </RadioButton>
  </View>
  );
});

if we using {example[0]}{example[1]}{example[2]}then we get next letters and if optn contain English words then no problem it will work but i have to manage these type of data so how to solve such issue. is it possible to use 'for loop' inside ?

2 Answers 2

2

That's weird but this seems to work :

<Text>{example.toString()}</Text>
Sign up to request clarification or add additional context in comments.

3 Comments

Invariant Violation:Objects are not valid as a react child(found: object with keys{key,index})
that's weird if your optn is effectively an array od strings. what is the output with <Text>{example.toString()}</Text>
Yeah that's worked . update in your answer i will accept
0

change example[0] to example, its not needed. when mapping, you get array values, what in your scenario is string, and with example[0] you select the first letter of string

objAns= this.state.optn.map((example,index) =>{
  return(
    <View  key={index.toString()} >
    <RadioButton currentValue={this.state.value} value={index+1} onPress={this.handleOnPress.bind(this)}>
    <Text>{example}</Text>
    </RadioButton>
  </View>
  );
});

2 Comments

Invariant Violation:Objects are not valid as a react child(found: object with keys{key,index})
please show console.log(example) and console.log(this.state.optn)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.