[英]tRPC mutateAsync returns nothing
This is my first attempt to use tRPC.这是我第一次尝试使用 tRPC。 I created a mutation named "add", which receive a URL as parameter and returns a hardcoded slug我创建了一个名为“add”的突变,它接收一个 URL 作为参数并返回一个硬编码的 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 ( {}
)但是,它只打印一个空的 object ( {}
)
What am I doing wrong?我究竟做错了什么?
Full source-code https://github.com/skhaz/url-shortener完整源代码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我正在使用 NextJS,在检查器上,在 .network 上,我可以在响应 JSON 上看到 slug 值
The problem is that I was using superjson
as the transformer.问题是我使用superjson
作为转换器。 Removing it solved the issue删除它解决了问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.