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

NextAuth - User stays logged in after token is expired

Right, I understand that maybe I should write some sort of callback or something that prompts the user to log in again, or maybe to refresh the token.. but I don't understand why this happens.

React-Dropzone, useState & dnd-kit struggles

What I want to achieve is the ability to drag image previews to change the order of the images, ie. something like this: https://codesandbox.io/s/dndkit-sortable-image-grid-py6ve?file=/src/App.jsx The images & their preview come from a react-dropzone component. There is a solid chance this is irrelevant to my issue but mentioning it to be sure. My initial plan was to have a state in the react-dropzone component inside of the onDrop: that will populate the useState into the following shape: { id: number, src: File }. This approach is similar to the example in the first codesandbox. but I don't see how I can do this without a useEffect, which feels overkill since this is really close to what I want to achieve: https://github.dev/HamedBahram/dropzone...

Export a Planetscale database.

Hello everyone, this question is related to Planetscale. I have a Planetscale db with 2 tables. Students and certificates. Each student has one certificate. Is there any way to export the data in order to read it with Excel?...

TRPC useQuery keeps refetching when switching pages? How can I cache the data on the client?

I recently migrated my project from CRA + React Query to T3 stack. I'm finding that on my client, all my queries called using useQuery are not being cached correctly. The whole React Query cache gets wiped when I go to a different page. In CRA this wasn't an issue, the query was cached until I invalidated it or it ran out of cache time. I'm not sure if there's an option I need to pass to the useQuery calls?...

Remote Markdown Best Practices

Any best practices when fetching remote markdown from a headless cms? If there is a project/article/video which covers this topic, i'll greatly appreciate it. Or some common mistakes / design patters to use to create maintainable and better code. Thanks!

Incorporate Rust into t3 stack

Im wondering if there is a good way to incorporate rust into a t3 app? Want to experiment writing some apis in rust and hopefully seeing some performance boosts #blazinglyfast 🙂...

How to replicate React Router Outlet like utility for Next.js?

A module in my Next.js application has a sidebar. I want to navigate to those paths without re-fetching the same data (that belongs to the parent component) from the API. The routing system of Next.js is restricting me to achieve the same. Is there any way I can replicate react-router "Outlet" like utility in Next.js? Thanks!...

pre-defining data in SSR?

Curious — can you use NextJS middleware to push data into getServerSideProps? Let’s say you have some global variable that gets reset every page refresh — but you need to populate through some API or pass it from the client. What’s a good way to populate the server with that global variable before it reaches a pages SSR

Is it possible to pass down a generic to my TRPC API route (procedure)?

From my front end, I need to pass a generic down to my TRPC procedure. Is this possible? The reason is because the fn that runs within the procedure will change the return types based on the generic it receives....

Is it okay to pass the _opt.req and _opt.res variables to createTRPCContext?

When using ssg to prefetch / fetch on the server (inside getServerSideProps), I need to pass a createContext object to the ssg: ``` const ssg = createProxySSGHelpers({ router: appRouter, ctx: createTRPCContext({...

Can I use tRPC useQuery inside getServerSideProps?

getServerSideProps is supposed to be async. Since the useQuery calls are synchronous, I get a type error: ``` Async function 'getServerSideProps' has no 'await' expression....

type checking error??

```import { GetServerSidePropsContext } from "next"; import { getServerAuthSession } from "../server/auth"; import { Session } from "next-auth"; type Callback = (data: { session: Session }) => void;...

Prisma multi schema CLI

Hello, Is it possible to only force reset one schema when using multiple schemas? For example, to push to db and reset everything in the database, you use something like ...

Typechecking sometimes break when trying to access fields on a variable

Sometimes when I try to access a variable, the type checking for it breaks and it gets typed as any . (See first image) giving this error: implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. But when I remove the line where I am trying to access the variable, it reverts back to its proper type and looks fine ( Second image). ...

Best CSS for this design

What would people say the best CSS for the following would be

TypeScript Intellisense is incredibly slow

I recently scaffolded a t3 app (manually, existing codebase) and found that the TypeScript Intellisense is incredibly slow. I am on a Macbook Air M1, and the only other thing running in the background is a Docker container housing a Postgres server. This makes it really hard to use TypeScript because I have to wait 10 seconds to get any autocomplete or intellisense. Copilot outpaces TypeScript by a good 5 seconds. I did some reading and heard that this could be caused by zod, but wanted to ask here first to see if anyone else has had similar problems....

Type a function based on its argument value.

I have a function that takes an object and a boolean (default to false). It will return an array of object with key id only if parameter bool of the function set to true. ```ts const helpMeTypeThis = (obj: MyObj, bool = false)...

mutation is returning void

I made a procedure that returns a string, but when I try to use it on my frontend, it's returning void instead of a string.

When I setup TRPC, is React Query pretty much being setup alongside it?

I moved a CRA app over to T3. In the CRA app I was using React Query to cache my data. After starting to use TRPC I realized that it's basically using React Query in the background. Is there basically no need now to do anything with React Query separately from TRPC?...