This is my first attempt to use tRPC. I created a mutation named "add", which receive a URL as parameter and returns a hardcoded slug
Router
export const entryRouter = router({
add: publicProcedure
.input(input)
.output(output)
.mutation(async ({ ctx, input }) => {
const slug = "test"
return { slug }
}),
})
Usage
const addEntry = trpc.entry.add.useMutation()
...
const { slug } = await addEntry.mutateAsync({ url: 'https://example.com' })
console.log(JSON.stringify({ slug })
However, it only prints an empty object ({}
)
What am I doing wrong?
Full source-code https://github.com/skhaz/url-shortener
PS. I am using with NextJS, on the inspector, on the network, I can see the slug value on the response JSON
The problem is that I was using superjson
as the transformer. Removing it solved the issue