Composables
useMutation()
The useMutation composable is a wrapper around the useMutation function from the Vue Query library. It provides a way to mutate data on the server and manage the state of the mutation.
<script lang="ts" setup>
const { mutate: addToCart } = useTRPC().cart.addProduct.useMutation({
onSuccess: () => {
console.log('Product added to cart')
},
})
function handleFormSubmit(productId: string) {
addToCart(productId)
}
</script>