Skip to content
Discussion options

You must be logged in to vote

Composables must be at the top level. So it becomes:

export const useObjectStore = defineStore('objectStore', () => {
	const db = useFirestore();

	const objectsRef = collection(db, 'objects');
	const currentObjectId = ref(0) // or maybe from the route?
	const { promise, data: object } = useDocument<Obj>(() => doc(objectsRef, currentObjectId.value));

	async fetchObject(objectId: string) {
		currentObjectId.value = objectId
		await nextTick() // from vue, we need to wait for changes to propagate
		await promise.value
		return object.value
	}
	
	return {
		object,
		fetchObject,
	};
});

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by posva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants