14th May 2020, 7:40 PM
cmcodes
cmcodes - avatar
3 Answers
+ 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.
19th May 2020, 5:45 AM
Burey
Burey - avatar
+ 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} } }
15th May 2020, 9:18 AM
Burey
Burey - avatar
0
I cannot hardcode subject values, they are being fetched from another component as array elements.
19th May 2020, 4:26 AM
cmcodes
cmcodes - avatar