useEffect(() => {
// It's important for this logic to be idempotent since React will call this twice
querySubjects.forEach(async (querySubject) => {
const matchingSubject = subjectsCollection.get(querySubject.id);
if (!matchingSubject && subjectsCollection.isReady()) {
try {
subjectsCollection
.insert({
name: displayLongOrShort(querySubject.name),
subject_id: querySubject.id,
hue: Math.floor(Math.random() * 360),
})
.isPersisted.promise.catch();
} catch (error) {
/* Blanket catch in case the sync happens and there was already such a row */
}
}
});
}, [querySubjects, subjectsCollection]);
useEffect(() => {
// It's important for this logic to be idempotent since React will call this twice
querySubjects.forEach(async (querySubject) => {
const matchingSubject = subjectsCollection.get(querySubject.id);
if (!matchingSubject && subjectsCollection.isReady()) {
try {
subjectsCollection
.insert({
name: displayLongOrShort(querySubject.name),
subject_id: querySubject.id,
hue: Math.floor(Math.random() * 360),
})
.isPersisted.promise.catch();
} catch (error) {
/* Blanket catch in case the sync happens and there was already such a row */
}
}
});
}, [querySubjects, subjectsCollection]);