Composables

useQuery()

The useQuery composable is a wrapper around the useQuery function from the Vue Query library. It provides a way to fetch data from an API and manage the state of the query.

Basic usage

<script lang="ts" setup>
const { data: shoppingCart } = useTRPC().cart.get.useQuery()
</script>

With parameters

You can pass input parameters directly to the useQuery function. These parameters can also be reactive.

<script lang="ts" setup>
const productId = ref(1)
const { data: product } = useTRPC().product.getById.useQuery(productId)
</script>

With options

You can pass any @tanstack/vue-query options as the second argument to the useQuery function.

<script lang="ts" setup>
const { data: notifications } = useTRPC().notifications.get.useQuery(undefined, {
  refetchInterval: 30000,
})
</script>

Copyright © 2024