A list of queries
Run one live query per item of a list that changes, the Vue way to do what Convex React's useQueries does.
Result
A dashboard shows one live card per pinned project. Pinning or unpinning a project adds or removes exactly one subscription.
Use one component per item
A component calls useConvexQuery in <script setup>, which runs once, so one component cannot call it a changing number of times. Give each item its own component instead. Each component owns its query, and Vue starts and stops it with the component:
<script setup lang="ts">
import type { Id } from '#convex/dataModel'
import { api } from '#convex/api'
const props = defineProps<{ projectId: Id<'projects'> }>()
const project = useConvexQuery(api.projects.get, () => ({ projectId: props.projectId }))
</script>
<template>
<article>
<p v-if="project.pending.value">Loading…</p>
<p v-else-if="project.error.value">{{ project.error.value.message }}</p>
<h2 v-else>{{ project.data.value?.name }}</h2>
</article>
</template><script setup lang="ts">
import { api } from '#convex/api'
const pinned = useConvexQuery(api.projects.pinnedIds, {})
</script>
<template>
<ProjectCard
v-for="projectId in pinned.data.value ?? []"
:key="projectId"
:project-id="projectId"
/>
</template>Use the item ID as the key. Then Vue keeps the existing cards when the list changes, and only new items start a query.
When one query is better
If the cards always appear together, one query that returns all of them is simpler and costs one function call instead of one per card. Use one component per item when the items change independently or come from different places.