Baboluo
Baboluo
TtRPC
Created by Baboluo on 6/10/2023 in #❓-help
Does trpc (t3 stack) disable ssr from Nextjs?
ssr/ssg/caching whatever adds a lot of complexity that is hard to reason about, really sucks tbh
3 replies
TtRPC
Created by Baboluo on 4/27/2023 in #❓-help
How to do an async API call in useEffect (T3 stack)
there's no server side state, its client side. the backend is an wraps an api that yields results of a machine learning model. thanks so far though, I don't want to waste your time so I'll just stick with this for now
16 replies
TtRPC
Created by Baboluo on 4/27/2023 in #❓-help
How to do an async API call in useEffect (T3 stack)
You think this is bad?
const [chatMessages, setChatMessages] = useRecoilState(chatMessagesState)
const [textareaText, setTextareaText] = useState("")
const [chatLoading, setChatLoading] = useState(false)
const ctx = api.useContext()

const sendUserMessage = useCallback(async () => {
if (textareaText === "") return
if (chatLoading) return

const currentMessages = [...chatMessages]
currentMessages.push({
id: uuidv4(),
role: "user",
text: textareaText,
addToPrompt: true,
})

setChatMessages(currentMessages)

setTextareaText("")
setChatLoading(true)

const answerMessage = await ctx.chat.queryTutor.fetch({
messages: currentMessages,
})
const messagesWithAnswer = [...currentMessages, answerMessage]

setChatMessages(messagesWithAnswer)
setChatLoading(false)
}, [
// ...
])
const [chatMessages, setChatMessages] = useRecoilState(chatMessagesState)
const [textareaText, setTextareaText] = useState("")
const [chatLoading, setChatLoading] = useState(false)
const ctx = api.useContext()

const sendUserMessage = useCallback(async () => {
if (textareaText === "") return
if (chatLoading) return

const currentMessages = [...chatMessages]
currentMessages.push({
id: uuidv4(),
role: "user",
text: textareaText,
addToPrompt: true,
})

setChatMessages(currentMessages)

setTextareaText("")
setChatLoading(true)

const answerMessage = await ctx.chat.queryTutor.fetch({
messages: currentMessages,
})
const messagesWithAnswer = [...currentMessages, answerMessage]

setChatMessages(messagesWithAnswer)
setChatLoading(false)
}, [
// ...
])
16 replies
TtRPC
Created by Baboluo on 4/27/2023 in #❓-help
How to do an async API call in useEffect (T3 stack)
Idk using state as means to drive useQuery is kinda opaque and unintuitive
16 replies
TtRPC
Created by Baboluo on 4/27/2023 in #❓-help
How to do an async API call in useEffect (T3 stack)
so mutation doesnt make sense intuitively
16 replies
TtRPC
Created by Baboluo on 4/27/2023 in #❓-help
How to do an async API call in useEffect (T3 stack)
Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects. from the docs. I don't do CRUD ops or perform server side-effects. just accessing a 3rd party API based on parameters from the user interface
16 replies