Skip to content
Discussion options

You must be logged in to vote

I realized the trpc object is being created by https://github.com/ottomated/trpc-svelte-query.

Copy pasting from the docs I managed to get this working

// +page.svelte
<script lang="ts">
    import { trpc } from '$lib/trpc';
    const query = trpc.greeting.query({ name: 'tRPC' });
</script>
  
{#if $query.isSuccess}
  <p>{$query.data}</p>
{:else if $query.isError}
  <p>{$query.error.message}</p>
{:else}
  <p>Loading...</p>
{/if}

The types weren't working because the result of trpc.greeting.query({ name: 'tRPC' }); is some kind of svelte auto subscribe object, and you need to prefix $ before use (i.e. $query.data to get the sting back).

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by tom-huntington
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant