[英]tRPC throws an error in setData (useContext wrapper of TanStack Query) after I updated it from v10-rc to v10
Before:
├── @tanstack/react-query@4.14.6
├── @trpc/client@10.0.0-rc.4
├── @trpc/next@10.0.0-rc.4
├── @trpc/react-query@10.0.0-rc.4
├── @trpc/server@10.0.0-rc.4
After:
├── @tanstack/react-query@4.14.6
├── @trpc/client@10.4.3
├── @trpc/next@10.4.3
├── @trpc/react-query@10.4.3
├── @trpc/server@10.4.3
這是我更新 tRPC 后拋出錯誤的代碼。
import { useStore } from 'src/store/store'
import { trpc } from 'src/utils/trpc'
export const useMutateItem = () => {
const utils = trpc.useContext()
const reset = useStore((state) => state.resetEditedItem)
const createItemMutation = trpc.item.createItem.useMutation({
onSuccess(input) {
const previousItems = utils.item.getAllItems.getData()
if (previousItems) {
utils.item.getAllItems.setData([...previousItems, input]) // Error message below
}
reset()
}
})
// ...
return { createItemMutation, ... }
}
(method) setData(input: void | undefined, updater: Updater<(Item & {
tags: Tag[];
})[] | undefined, (Item & {
tags: Tag[];
})[] | undefined>, options?: SetDataOptions | undefined): void
@link — https://react-query.tanstack.com/reference/QueryClient#queryclientsetquerydata
Expected 2-3 arguments, but got 1.ts(2554)
utilsProxy.d.ts(46, 45): An argument for 'updater' was not provided.
闡明方法;
setData(input: void | undefined, updater: Updater<...>, options?: SetDataOptions | undefined): void
我想問題在於“輸入”參數必須為 void 或 undefined。 我該如何解決這個問題? TanStack 查詢文檔中的“queryKey”和 tRPC 包裝器中的“input”有什么區別? GitHub 上有一個錯誤報告,但可能無關。
試試這個
utils.item.getAllItems.setData((() => {})(), [...previousItems, input])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.