[Vue warn]: inject() can only be used inside setup() or functional components. #1439
Replies: 3 comments
-
@posva Instead of changing the ref value, I tried to use the 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',
},
);
watch(selectedDay, () => {
- entries.value = useCollection<Entry>(
+ 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()),
),
{
+ target: entries,
ssrKey: 'entries',
},
- ).value;
+ )
}); But I get this warning now:
If I understand the message correctly, this suppose that the 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',
},
); |
Beta Was this translation helpful? Give feedback.
-
I even changed my code to use computed for +const startWeek = computed(() => {
+ return $moment(selectedDay.value).startOf('week').toDate();
+});
+const endWeek = computed(() => {
+ return $moment(selectedDay.value).endOf('week').toDate();
+});
+
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()),
+ where('date', '>', startWeek.value),
+ where('date', '<', endWeek.value),
),
{
ssrKey: 'entries',
},
); |
Beta Was this translation helpful? Give feedback.
-
Closing in favor of #1436 |
Beta Was this translation helpful? Give feedback.
-
Reproduction
https://github.com/mrleblanc101/neobigben/tree/feature/firebase
Steps to reproduce the bug
Expected behavior
I do not use SSR, I use
generate
withssr: false
, I should not get an SSR error ?Actual behavior
I get this error when using a watch inside a Pinia setup store when using vue-fire useCollection to change the
where
filter dynamically.Additional information
No response
Beta Was this translation helpful? Give feedback.
All reactions