Theo's Typesafe Cult

TTC

Theo's Typesafe Cult

Join the community to ask questions about Theo's Typesafe Cult and get answers from other members.

Join

Does invalidate(); perform an actual refetch?

I am half way into the course video and I see void ctx.post.getAll.invalidate(); to show the new post we are making. Isn't this just refetching? Wouldn't it be better to have a local state/catch being updated when successful vs trying to refetch everything all over again? just seems very costly especially if an app grows. Please let me know if I am wrong in my thinking or how I should be thinking when we consider refetching data once successful. Thank you
Solution:
on personal projects where I know perfectly the architecture and every API call being made, I always update the cache, and set the stale duration to Infinity. On enterprise projects where 50 devs work on the same app, sometimes it's just a mess and you'd have to update 7 different cache entries and know exactly how the data is structured in each, so we tend to just invalidate

SWR - array of data in one request, one item from array in another

So I am using SWR in my nextJS app and I have two routes GET /courses gets all classes you are enrolled in (of type CourseData[]) GET /courses/:course_id gets specific details for one course (of type CourseData)...

Clerk re-render parent server component on sign out with custom sign out button.

Hi I'm probably being a little stupid here but I'm just wondering what the best and most simple way to create a custom sign out button when using Clerk? I was able to create a Sign out button with the following code but the parent server component wouldn't rerender so I needed to refresh for it to show me as logged out: ```tsx export const CustomSignOut = () => { const { signOut } = useClerk();...
Solution:
just figured out what AfterSignInURL and AfterSignOutURL were 🤦

Prisma schema question

How can I efficiently maintain a user's balance in a database given the following prisma schema, where the balance is the sum of all trades profitAndLoss? Should I store the balance as a field in the User model and update it manually or should I aggregate it from the Trade model on every request? How can I ensure that the balance stays up-to-date when old trades are removed or modified?

T3 Firebase solution? (SMS OTP Auth)

I know I know, we love Auth.js and Clerk. But there's a problem when it comes to SMS authentication. OTP authentication via SMS is expensive (especially outside the USA, in some countries being 26cents/message). The best solution that I found is Firebase, that gives you 10,000 successful sign ups/month for free. So if you are a broke developer and want to implement SMS auth for your app, Firebase is your only choice. It would be nice to have a guide to implement Firebase into a T3 and T3 Turbo project. The firebase auth library is not as straight forward as Clerk or Next.js and I'm having some problems implementing the required middleware for the tRPC server....

How do I make Jotai work with trpc on the t3 stack?

I am having trouble finding ways to work with Jotai and trpc on nextjs.

Any recommend open source react project?

I am trying to optimize the project of company. It is like a CRUD based shopping web. I do use tanstack query for data fetching, zustand as global data center, react-hook-form and zod. They did help....

Rendering a blob in Nextjs

I am having difficulties rendering an image which is restored in form as link and when i console.log i get a blob,below is how i implemented it, ``` const [vname,setVname] = useState('') const [vfile,setVfile] = useState<File |null>(null) const [selectedValue, setSelectedValue] =useState({category:'dance'})...

What's the difference between React.ComponentProps and React.PropsWithChildren ?

I just saw someone post something on youtube but didnt't really explain it. Whats the difference between these 2, and when should I use either? Except the obvious part that the Component... has the types already included and you just call the type of element. ```...

nextra with tailwindcss

through the uploadthings docs i found out about nextra ... i would like to use tailwind but i cant get it to work, can someone help me (i use the docs template from the nextra docs)

How to use next-auth/clerk.js for getting user session

```ts /** server/uploadthing.ts */ import { createFilething, type FileRouter } from "uploadthing/server"; const f = createFilething(); ...

Error with mdx file webpack parser

I am trying to integrate an MDX files that I want blog articles in. I have a component <ArticleLayout meta={meta} {...props} /> I am using a TailwindUI template as a backbone for the some of the implementation and there it works fine. https://tailwindui.com/templates/spotlight ```...

How to debug Vercel cache misses with tRPC?

Basically. I have a tRPC endpoint with the following NextApiHandler config: ```ts export default createNextApiHandler({ router: appRouter,...

How do you run a one-off prisma script?

Hello 👋 I'm trying to run a little script to change some stuff in my database. Kind of like a prisma seed or some sort of scripted migrate . I need to be in a JS environment (not just SQL) so I can run some logic, and I also need to import some functions from the rest of my codebase. The issue is the classic "node is bad at importing web stuff" and "typescript needs to be compiled". So I'm trying ts-node but it doesn't solve the importing issues. I've tried many variations of this script in my package.json...

Where to run a kinda `cron` specific for each user?

I have the necessity to run a function each hour, this function will add some data into different database tables so I do not want to rely on a cron because, if the user stops to use the platform, I'll end up just adding trash to the database for no reason. So my idea is to go into the auth.ts and use the session event provided to go and fetch the lastRun column of my user profile. If the difference between now and lastRun is more than 1 hour, I'll call the function that will do all the things that has to do....

Fire trpc useQuery only when a callback is called

I have kind of a weird use case. I would like to run a trpc useQuery() only when a callback is called. This callback is triggered by a push notification so I don't want the query to update on its own, only when the callback fires. How can i do this?...

Should I use Tanstack router

I'm kinda new to all this, I'm at an early stage of building a website, I saw theo talking about tanstack router. While it's still in beta, I'm not sure if I should use it. Also, I have no idea why the default routing is not good enough or how this lib improves over the others. Should I just use react router to navigate between pages?...

File Upload Supabase + T3 Stack

Hey how would I go about uploading a file with the t3 stack and supabase with a form so basicly I have a form with questions like: server name? description? and then I have a image upload field I dont know how I would upload the image and get the url and store in the database can anyone please help me thanks!!...

How do I set the default useState value of a trpc call?

EDIT: Sorry apparently I can't rename the title. I meant to say: 'How do I set a default useState value to something that came from a trpc call' Hi folks, so I need some help with my component It's a simple team switcher. I need help understanding a few things. I have two main trpc endpoints: getAllForLoggedUser and switchActiveWorkspace....

Spotify login on Clerk not working on new users

Hey! I have a strange problem: If I try to login via Spotify with a user that already exists on clerk users everything goes fine. But if I try to login with a new user (new Spotify account) I am getting the following error: "Unable to complete action at this time. If the problem persists please contact support." Couldn't find anything about this online, but the stranger thing is that after brute force trying to login again and again with a new account it finally worked. Then I logged out , tried to login again with the same Spotify account (after only 1-2 minutes) and I got the error again....