+ 2
Update and access array elements by index in a FlatList in React Native
3 ответов
+ 2
I didn't say you should hard code them
Just suggested a different structure.
You can make a function that transform the array to that structure.
+ 1
You haven't asked anything here nor on stackoverflow.
But a brief look at your code shows you are doing something wrong
present_count and total_count starts as empty arrays, but when using setState they are overwritten to be integers (which happens right away on the componentDidMount lifecycle)
You need to take different approach to update an array element in an index, or try to restructure your app altogether to work with a different datatype, an object for example:
state = {
subjects: {
"C++": {present: 8, total: 20}
}
}
0
I cannot hardcode subject values, they are being fetched from another component as array elements.