TanStackT
TanStack2y ago
1 reply
spotty-amber

queryKey works as string but not with number

Hi guys!

I've a query key: detail: (id: number) => ['decks', 'item', id],

When I make an edit mutation I got a result from the server, where id is number. So i use setQueryData with it.
return useMutation({ mutationFn: (body: DeckEditableType) => patchDeck(params.deckId, body), onSettled: (data) => { if (data) { queryClient.setQueryData(DECK_QUERY_KEYS.detail(data.id), data)

When I do this it will not refresh my detail screen where I use the next query:
export const useGetDeckByIdSuspenseQuery = (params: { deckId: number }, options?: {}) => useSuspenseQuery({ queryKey: DECK_QUERY_KEYS.detail(params.deckId), queryFn: () => getDeckById(params.deckId), ...options, })

But if I use the queryKey as string it works. The detail screen refreshing well.
detail: (id: number) => ['decks', 'item', id.toString()],

Why? What's wrong? Why number not works well.
Thank you!
Was this page helpful?