Closed aaronbentley closed 2 years ago
You probably figured it out by now but I'm gonna answer it just to leave registered.
You should wrap the collection function inside the query function alongside the orderBy function.
const [ingrs, ingLoading, ingError] = useCollectionData(
query(collection(firestore, `users/${user?.uid}/ingredients/`), orderBy('id', 'desc'))
)
Of course, both orderBy and query should be imported as modules like collection is.
import { collection, orderBy, query } from 'firebase/firestore'
Thank you @renbesson 🙌
Appreciate you taking the time to help me out here - have a great day my friend 🥳
Hello everyone 👋
Unfortunately I'm super tired today, and have that sinking feeling I've missed something trivial. I'm trying to add an orderBy clause to the
useCollection
hook, the following works without an orderBy clause:However, if I add an orderBy clause (using the field 'timestamp') to the
collection
like so:... I get the following console error:
Where am I going wrong here? Is my primary issue a lack of sleep? 🥱
Thanks for taking the time to look at my issue.