Skip to content

Commit

Permalink
docs: add useMutation example
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano committed Dec 7, 2023
1 parent f45957b commit 93a27a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 10 additions & 0 deletions docs/content/1.get-started/3.client.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,21 @@ As you can see, we passed `AppRouter` as a type argument of `createTRPCNuxtClien
<script setup lang="ts">
const { $client } = useNuxtApp()
// With composables
const getUser = await $client.getUser.useQuery('id_bilbo');
// => { data: { id: 'id_bilbo', name: 'Bilbo' }, pending: false, error: false };
const createUser = await $client.createUser.useMutation();
await createUser.mutate({ name: 'Frodo' });
// => { data: { id: 'id_frodo', name: 'Frodo' }, pending: false, error: false };
// With vanilla
const bilbo = await $client.getUser.query('id_bilbo');
// => { id: 'id_bilbo', name: 'Bilbo' };
const frodo = await $client.createUser.mutate({ name: 'Frodo' });
// => { id: 'id_frodo', name: 'Frodo' };
</script>
Expand Down
6 changes: 2 additions & 4 deletions playground/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ const addTodo = async () => {
completed: false
}
data.value.push(newData)
const result = await mutate(newData)
await mutate(newData)
await refreshNuxtData(todosKey)
data.value.push(result)
}
</script>

Expand Down

0 comments on commit 93a27a6

Please sign in to comment.