Skip to content
Advertisement

How to sum up data in the rendered component in react?

I want to sum up each multiplication of weights and repeats that belong to the same trained_at string. Currently I realize the “grouping” of dates by comparing the current date string with the previous date string in the render part of my component.

In my code example that is fully working you can find a Sum here comment, where I want to render the calculation result.

My sample data is coming from Firestore in the real app and does not have that calculation. Thus I need to calculate after fetching the result.

This is what I got rendered:

JavaScript

This is what I want to accomplish:

JavaScript

And this is my code:

JavaScript

Advertisement

Answer

You need to first re-group the items and calculate the sum, then display them.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement