Might be a very simple answer. But I'm unable to find a gen 2 example of how to sort the results from an observeQuery.
You can see the subscription code below. But I cannot find a sort, or sortDirection option in the function docs.
const sub = client.models.Display.observeQuery({
authMode: "userPool",
filter: { orgID: { eq: orgID } },
}).subscribe({
error: (error) => {
console.log("error observe query:", JSON.stringify(error, null, 2), orgID)
// setErrors(error)
},
complete: () => {
console.log("complete")
},
next: ({ items, isSynced }) => {
console.log("DisplayScreen updated", JSON.stringify(items, null, 2))
setDisplays(
items.sort((a, b) =>
a.createdAt && b.createdAt ? (a.createdAt < b.createdAt ? 1 : -1) : 0,
),
)
setDisplayCount(items.length)
setIsSyncedState(isSynced)
},
})
return () => sub.unsubscribe()
}, [orgID])