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], }; });
Was this page helpful?