React Native: SectionList get header from renderItem

1.8k views Asked by At

I am trying to get header name from renderItem but it giving me undefined. I need the name for a checklist so that's why I am trying to pass it to renderItem.

This is my code can anyone help me out?

const List = (props) => {
  const list = [
    {
      "id": "G1600789684218",
      "data":  [
         {
          "id": "G1600789684218",
          "value": "Going Skating",
        },
      ],
      "name": "Jack Ross",
    }
  ]

  const renderList = ({ item }, name) => {
    console.log("item name is", name);
    return (
      <View>
        <ListItem title={item.value} />
      </View>
    );
  };
  return (
    <SectionList
      sections={list}
      keyExtractor={(item, index) => index}
      renderSectionHeader={({ section: { name, data } }) =>
        <Text style={styles.heading}>{name}</Text>
      }
      renderItem={renderList}
    />
  );
};

export default List;
1

There are 1 answers

0
senthil balaji On BEST ANSWER

I think, your renderList should be like,

// section has entire data passed for section
  const renderList = ({ item, section }) => {
    console.log("item name is", section.name);
    return (
      <View>
        <ListItem title={item.value} />
      </View>
    );
  };