BadBoy
BadBoy
Explore posts from servers
TTCTheo's Typesafe Cult
Created by BadBoy on 1/13/2025 in #questions
useQuery or useMutation?
What's the best way to handle side effects with React Query when making API calls in a chat application? I'm building a chat app where each API response needs to update a conversation array in state. Currently using useQuery with side effects in the queryFn, but I know this isn't ideal. Here's my current code:
const getAnswer = useQuery({
queryKey: ["getAnswer", lastConversation?.content],
queryFn: async () => {
// API call + state updates here
},
enabled: currentStage === STAGES.FINAL_ANSWER,
});
const getAnswer = useQuery({
queryKey: ["getAnswer", lastConversation?.content],
queryFn: async () => {
// API call + state updates here
},
enabled: currentStage === STAGES.FINAL_ANSWER,
});
Is useMutation a better choice here? Or should I handle state updates in a separate useEffect?
10 replies
TTCTheo's Typesafe Cult
Created by BadBoy on 12/26/2022 in #questions
I was trying to setup TRPC in NextJS, but I am getting this error somehow, no idea why it is?
8 replies