T
TanStack3y ago
eager-peach

how to update query state from websocket?

I receive a new object via websockets that I need to add to the offline state. I tried to do this using setQueryData, but sometimes oldData is undefined, even though the data has already been loaded in useQuery. Can you suggest what I might be doing wrong? Perhaps I should use a different method? Example usage in a component: const { data, isLoading, isFetching: isValidating } = useQuery<IConversation>(["singleChat"], () => fetchSingleChat(/chats/${id})); Trying to update conditionally in websockets: queryClient.setQueryData(["singleChat"], (oldData) => { console.log('oldData: ', oldData); const oldDataTyped = oldData as IConversation; return { ...oldDataTyped, results: [data.payload, ...oldDataTyped.results], }; });
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?