Jonathan.Alphonso
Jonathan.Alphonso
TTCTheo's Typesafe Cult
Created by Jonathan.Alphonso on 1/14/2024 in #questions
How to configure Vitest in T3?
Hello everyone, I'm currently working on implementing the Vitest example for TRPC as outlined in the T3 documentation (https://create.t3.gg/en/usage/trpc#sample-integration-test), but I'm encountering some challenges. Despite following the guide and setting up everything as suggested, I'm facing "no test" errors when running Vitest.




I have already set up the necessary environment and configurations as per the T3 Stack documentation. However, I seem to be missing something or doing something wrong as the tests aren't being recognized or executed properly. Has anyone here successfully implemented this Vitest example for TRPC testing? I would appreciate any insights or suggestions on what might be going wrong or any steps that I might have overlooked. Thanks in advance for your help!
1 replies
TTCTheo's Typesafe Cult
Created by Jonathan.Alphonso on 11/5/2023 in #questions
Unwanted Re-renders with Custom Hook in Next.js (T3)
Hello everyone, I'm currently working on a Next.js project and I'm facing an issue with unwanted re-renders. I have a custom hook useStories that fetches stories from an API. This hook is used in my AllUserStories component. You can see the page the component is rendered at: https://ai-fight-pits.vercel.app/stories Here's the code for the useStories hook: https://github.com/JonathanAlphonso/ai-fight-pits/blob/main/src/hooks/useStories.ts And here's the AllUserStories component: https://github.com/JonathanAlphonso/ai-fight-pits/blob/main/src/pages/stories/index.tsx The problem I'm facing is that the AllUserStories component is re-rendering multiple times, and the useStories hook is being called more times than I expect. I've tried using useMemo to memoize the return value of useStories, but it didn't solve the issue. Here are the logs I'm getting when I added console logs to various files:
useStories hook called
AllUserStories rendered
Session data: undefined
Session status: loading
Stories: []
Is loading: true
AllUserStories rendered
Session data: undefined
Session status: loading
Stories: []
Is loading: true
useStories hook called
AllUserStories rendered
Session data: {user: {...}, expires: '2023-12-05T22:17:06.022Z'}
Session status: authenticated
Stories: []
Is loading: true
useStories hook called
AllUserStories rendered
Session data: {user: {...}, expires: '2023-12-05T22:17:06.022Z'}
Session status: authenticated
Stories: []
Is loading: true
useStories hook called
AllUserStories rendered
Session data: {user: {...}, expires: '2023-12-05T22:17:06.022Z'}
Session status: authenticated
Stories: (5) [{…}, {…}, {…}, {…}, {…}]
Is loading: false
useStories hook called
useStories hook called
AllUserStories rendered
Session data: undefined
Session status: loading
Stories: []
Is loading: true
AllUserStories rendered
Session data: undefined
Session status: loading
Stories: []
Is loading: true
useStories hook called
AllUserStories rendered
Session data: {user: {...}, expires: '2023-12-05T22:17:06.022Z'}
Session status: authenticated
Stories: []
Is loading: true
useStories hook called
AllUserStories rendered
Session data: {user: {...}, expires: '2023-12-05T22:17:06.022Z'}
Session status: authenticated
Stories: []
Is loading: true
useStories hook called
AllUserStories rendered
Session data: {user: {...}, expires: '2023-12-05T22:17:06.022Z'}
Session status: authenticated
Stories: (5) [{…}, {…}, {…}, {…}, {…}]
Is loading: false
useStories hook called
I'm not sure why the useStories hook is being called so many times and why the AllUserStories component is re-rendering so many times. Any help would be greatly appreciated! Thank you in advance.
8 replies
TTCTheo's Typesafe Cult
Created by Jonathan.Alphonso on 8/8/2023 in #questions
running vercel edge api functions?
Trying to use vercel edge functions for my trpc api routes. Having a hard time with this. Any advice?
8 replies
TTCTheo's Typesafe Cult
Created by Jonathan.Alphonso on 7/25/2023 in #questions
best way to do rate limiting for API Calls?
I have a web app that calls gpt's API to create a fun little fight story between 2 characters. Code and demo site are detailed at: https://github.com/JonathanAlphonso/ai-fight-pits Api call in question is at Ai-fight-pits/src/server/api/routerd/gpt.ts My fear is that people will spam requests are rack up my gpt api bill. I like the idea of not needing to log in to generate a fight, so maybe limiting people by IP would be good? Theo's t3 tut limits people by used ID in upstash but I don't think that's a good fit if I don't want to require logins. Any tips???
3 replies