Having trouble determining how to calculate the total of an array received from an API request. Working with Next.js
{positions.map(position => {
return (
<List
title={position.title}
slug={position.slug}
quantity={position.quantity}
position={position.position}
price={position.transactionPrice}
fees={position.fees}
code={position.assetType.code}
assetName={position.assetType.name}
assetType={position.assetType.__typename}
/>
);
})}
I aim to sum certain fields (e.g., fees) to display above the list, showing the combined fees for all entries. I've been informed that this cannot be done through the GraphQL API call. How can I achieve this in Next.js/React?
I believe I need to utilize the reduce array method, but unsure where and how to incorporate it into the code. Should it precede the return() statement?