I was reading on how it is possible to update existing query data with Query Client's setQueryData method.
Here is how I transform my data.
{
select: (data) => {
let fullDaysArray = [] as Day[];
data.docs.map((docSnapshot) => {
const { id } = docSnapshot;
let data = {
...docSnapshot.data(),
documentId: id,
} as Day;
fullDaysArray.push(data);
});
fullDaysArray.sort((a, b) => a.order - b.order);
return fullDaysArray;
},
I did it like this:
queryClient.setQueryData("currentDiary", newData);
However I started getting these errors:
TypeError: Cannot read properties of undefined (reading 'map')
And that is because, the newData that I am setting is not a firebase object that looks like this:
Fu {_firestore: La, _userDataWriter: dh, _snapshot: qo, metadata: $u, query: Sa}, but the actual already transformed object that looks like this:
[
{
dayName: "Monday",
order: 1,
uid: "1234",
//...
Which obviously fails data.docs.map((docSnapshot)
Is there a way for me to only update the variable that I am returning from select: (data) method, which would be fullDaysArray?