ryanagillie
ryanagillie
Explore posts from servers
TTCTheo's Typesafe Cult
Created by ryanagillie on 6/3/2023 in #questions
GitHub Action Failing Type-Checks but Working Locally
54 replies
TTCTheo's Typesafe Cult
Created by ryanagillie on 11/14/2022 in #questions
tRPC useQuery ReturnType
Working on a custom auth provider (just wanted to do all the stuff myself, learn the flow, ya know) and trying to get the result of a trpc useQuery passed through context. I can't seem to figure out how to type the context, as the data always comes out as unknown.
import { procedure, router } from "../t";

export const auth = router({
session: procedure.query(() => null),
});
import { procedure, router } from "../t";

export const auth = router({
session: procedure.query(() => null),
});
import { createContext, useContext } from "react";

import { type Uninitialized, uninitialized } from "client/react/context";
import trpc from "client/trpc";

type SessionContext = Pick<ReturnType<typeof trpc.auth.session.useQuery>, "data" | "status">;
// hovering in VSCode gives me:
// type SessionContext = {
// data: unknown;
// status: "error" | "success" | "loading";
//}
const sessionContext = createContext<SessionContext | Uninitialized>(uninitialized);

export const useSession = () => {
const session = useContext(sessionContext);
if (session === uninitialized) throw new Error("useSession Must Be Used Within A SessionProvider");
return session;
}

export type SessionProviderProps = {
children: React.ReactNode;
};
export const SessionProviderProvider = ({ children }: SessionProviderProps) => {
const { data, status } = trpc.auth.session.useQuery();
// ^^^^ correctly typed as null (placeholder)

return (
<sessionContext.Provider value={{ data, status }}>{children}</sessionContext.Provider>
// ^^^^ not correctly typed (unknown)
)
}
import { createContext, useContext } from "react";

import { type Uninitialized, uninitialized } from "client/react/context";
import trpc from "client/trpc";

type SessionContext = Pick<ReturnType<typeof trpc.auth.session.useQuery>, "data" | "status">;
// hovering in VSCode gives me:
// type SessionContext = {
// data: unknown;
// status: "error" | "success" | "loading";
//}
const sessionContext = createContext<SessionContext | Uninitialized>(uninitialized);

export const useSession = () => {
const session = useContext(sessionContext);
if (session === uninitialized) throw new Error("useSession Must Be Used Within A SessionProvider");
return session;
}

export type SessionProviderProps = {
children: React.ReactNode;
};
export const SessionProviderProvider = ({ children }: SessionProviderProps) => {
const { data, status } = trpc.auth.session.useQuery();
// ^^^^ correctly typed as null (placeholder)

return (
<sessionContext.Provider value={{ data, status }}>{children}</sessionContext.Provider>
// ^^^^ not correctly typed (unknown)
)
}
16 replies
TTCTheo's Typesafe Cult
Created by ryanagillie on 9/22/2022 in #questions
SSR useQuery Breaking Page Transition
Technically using an infinite query, but I have an array of Posts that I'm prefetching, but when I use a next.js Link I get an undefined error during the transition
6 replies
TTCTheo's Typesafe Cult
Created by ryanagillie on 9/19/2022 in #questions
tRPC Query being called client side even with dehydrated state
I have a trpc v10 prefetch in gssp, it's being passed in correctly and hydrated properly, but the query is still being called client side
9 replies
TTCTheo's Typesafe Cult
Created by ryanagillie on 9/19/2022 in #questions
Next Future Image Rounded?
15 replies