Firebase and "none" in arrays - peophins-plasmas/pawsome-app GitHub Wiki

In the petForm component and other components where data is added to Firebase, if a possible array is sent to Firebase, if a datatype being submitted is an array, and it is empty, it is sent with an element "none".

When querying Firestore data with "in", an error is thrown if the Firestore data is an empty array. Including the first element "none" prevents this error from being thrown.

All logic surrounding retrieving data from arrays or mapping arrays accounts for an element being "none". In incidences where data is retrieved from a matching data (.where("userId", "==", userId) retrieves the document whose userId field matches the current userId variable, for example), none will not be matched and therefore does not need to be checked for. In cases where "none" might be included in an array, logic checks also check for the presence of a "none" element.

For example, since pets in the AddTask component may include "none", and because pets are pushed into the array during the Firestore query in the order they are found, one map function on pets check that the last element is not none to ensure the array is not empty. if (user.ownedPetId.length !== petIdArray.length || user.ownedPetId[user.ownedPetId.length - 1] === "none" ) Since push places elements onto the end of the array, if the last element is "none", no elements have been added; otherwise, there exist pets within this array even if the first element is "none".