2

I couldn't understand why it is not working. It is showing me error cannot find name 'contentItem'. Any suggestions ?

const CONTENT = [ { title: 'Лицевой счет 256215492543', sub_title: 'ул.Неизвестная, 78/9,', count: true }, { title: 'Лицевой счет 12356215492543', sub_title: 'ул.Неизвестная, 72/7,', count: false }, .... renderContent(section, _, isActive, CONTENT) { return ( CONTENT.map(contentItem => ( if (contentItem.special) { return( <View> <Text>{contentItem.title} spec</Text> </View> ) } return( <View style={{backgroundColor:'red'}}> <Text>{contentItem.sub_title} </Text> </View> ) }); 

Basic idea, is to show TITLE if "count" is TRUE, if "count" false show SUB_TITLE

2
  • how are you calling the renderContent can you show? Commented Oct 25, 2019 at 10:47
  • <Accordion activeSections={activeSections} sections={CONTENT} touchableComponent={TouchableOpacity} expandMultiple={true} renderHeader={this.renderHeader} renderContent={this.renderContent} onChange={this.setSections} /> Commented Oct 25, 2019 at 11:29

1 Answer 1

3

I change the map function, in the js array map function, it will have three arguments, you can look at the API about map

const CONTENT = [ { title: 'Лицевой счет 256215492543', sub_title: 'ул.Неизвестная, 78/9,', count: true }, { title: 'Лицевой счет 12356215492543', sub_title: 'ул.Неизвестная, 72/7,', count: false }, renderContent(section, _, isActive, CONTENT) { return ( CONTENT.map((item,index)=> { if (item.count) { return( <View key={index}> <Text>{item.title} spec</Text> </View> ) } return( <View key={index} style={{backgroundColor:'red'}}> <Text>{item.sub_title} </Text> </View> ) }}; 
Sign up to request clarification or add additional context in comments.

4 Comments

What has changed here? Have you fixed the code? Please include an explanation of what this answer achieves
add key prop to <View> because you are rendering it in a map function. otherwise it will throw a warning.
Why we need "index " as second parameter ?
@Jasur Kurbanov the second parameter is not needed, I only want to show it arguments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.