I am trying to make a simple app where I could record shrinkage of material. The input parameters are the first and second material thickness. Below is my fetch data where I query through the values I would like to display and this works fine for displaying those filtered items.
I try and only set my delta values inside my collection I console.log the array to see what is inside and also try to find the sum of this array.
const [firstPara, setFirstPara] = useState("");
const [secondPara, setSecondPara] = useState("");
const [deltaList, setDeltaList] = useState([0]);
const [theAmountData, setTheAmountData] = useState(null);
const fetchData = async () => {
const weldShrinkageQuery = query(collection(db, "WeldShrinkageRecord"),
where("firstMaterialThickness", "==", firstPara),
where("secondMaterialThickness", "==", secondPara),
);
const theData2 = await getDocs(weldShrinkageQuery);
setTheAmountData(theData2.docs.length)
setDeltaData(theData2.delta)
// filter only delta values inside of query
const filteredDeltaValues = theData2.docs.map((doc) => ({
delta: doc.delta,
}))
setDeltaList(filteredDeltaValues);
console.log("this is the array: " + deltaList)
// try to find addition of array
let addition = deltaList.reduce((value, sums = 0) =>
sums = sums + value.delta);
console.log(addition)
};
this is how my values are stored in firestore:
when running the script I get: