React Native SectionList replace data key
Asked Answered
S

1

7

I am fairly new to React and React native, but I have bumped into a problem when populating a SectionList and could not find a solution yet.

I have an array of objects, and each object has it's own array. A SectionList is ideal to display this info, however, the array for each section is not called "data", while SectionList seems to expect the key "data" for the array in each section.

Is there a way to tell the SectionList to use another key instead of the data key to populate each section's array?

Swordplay answered 24/7, 2018 at 6:2 Comment(0)
K
1

As Per my Knowledge on SectionList each Section will Expect a data and Key .

What you can do is modify your Data as per that.

like for Eg : your data is [[1,2,3],[4,5],[6,7]]

what you can do is iterate through this array and push each subArray into New Array With Format {key:index,data:subArray}

hope this will Help :)

Kania answered 15/2, 2019 at 14:21 Comment(4)
Its an extra processing involved.... .there should be an option to provide the key that holds the array instead of hardcoding it to "data"Act
i do agree with your point and there should be a prop where you can provide key of array, will try to discuss it further in react native discussion.Kania
Is there really no solution to this? Everyone is just out there beating their data to be inside a data key?...Hasty
yes for now there is no solution. Someone can always try to implement it and send a PR. I wanted to do it but faced challenges in setting up for contributing. if someone can help me with that i will try implement it and send a PR.Kania

© 2022 - 2024 — McMap. All rights reserved.