wobsoriano / trpc-nuxt

End-to-end typesafe APIs in Nuxt applications.
trpc-nuxt.vercel.app
MIT License
675 stars 38 forks source link

feat: useMutation composable #132

Closed wobsoriano closed 10 months ago

wobsoriano commented 10 months ago

This PR adds a useMutation composable kinda similar to TanStack Query useMutation:

<script setup lang="ts">
const { $client } = useNuxtApp()

const { mutate, pending, error } = $client.login.useMutation()

const handleLogin = () => {
  const name = 'John Doe';
  mutate({ name });
}
</script>

<template>
  <h1>Login Form</h1>
  <button
    :disabled="pending"
    @click="handleLogin"
  >
    Login
  </button>
  <div v-if="error">
    Something went wrong
  </div>
</template>

Needs improvement but it works for now!

vercel[bot] commented 10 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
trpc-nuxt ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 7, 2023 5:01am