Composables

key()

You can get the query key by calling the key() function. With the key you can access all the other Tanstack Query features.
<script lang="ts" setup>
const trpc = useTRPC()
const cartKey = trpc.cart.get.key()

const productKey = trpc.product.getById.key(1)

// eg. cancel queries by key:
const queryClient = useQueryClient()
await queryClient.cancelQueries({ queryKey: cartKey })
</script>

Copyright © 2024