Skip to content

Dynamic ref in where clause #1436

Closed Answered by posva
mrleblanc101 asked this question in Questions and Help
Oct 6, 2023 · 5 comments · 7 replies
Discussion options

You must be logged in to vote

You are very close! You need to pass a reactive value to useCollection() there are some extra tips in docs but this is the shortest version, passing a function getter:

const entries = useCollection<Entry>(() =>
    query(
        collection(db, 'entries').withConverter(dateConverter),
        where('user', '==', user.value?.uid),
        where('date', '>', $moment(selectedDay.value).startOf('week').toDate()),
        where('date', '<', $moment(selectedDay.value).endOf('week').toDate()),
    ),
    {
        ssrKey: 'entries',
    },
);

Watchers are not meant for this, neither are passing the useCollection() to a computed(), it's the other way around. The lightest is just a useCollection((…

Replies: 5 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@mrleblanc101
Comment options

Answer selected by posva
Comment options

You must be logged in to vote
6 replies
@posva
Comment options

@posva
Comment options

@mrleblanc101
Comment options

@mrleblanc101
Comment options

@posva
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants