Samip Poudel
Samip Poudel
TTCTheo's Typesafe Cult
Created by Samip Poudel on 4/21/2024 in #questions
Improving Next.js Monolith
Hi Everyone! I have a question about architecting my app. Currently I have a single (massive) Next.js 12 app that powers websites for multiple domains. This is because all of these domains have similar website and share many pages and components. Currently what it does is check domain client-side and render website accordingly (themes & content as per the domain). But as it is growing, its becoming slow. What would be a better way to build websites like these. What is the standard practice in this case?
2 replies
TTCTheo's Typesafe Cult
Created by Samip Poudel on 1/24/2023 in #questions
useReducer with TypeScript
What's the best way to write this useReducer in TypeScript:
const [{ firstName, lastName }, setName] = useReducer(
(prev, next) => ({ ...prev, ...next }),
{
firstName: "",
lastName: ""
}
);
const [{ firstName, lastName }, setName] = useReducer(
(prev, next) => ({ ...prev, ...next }),
{
firstName: "",
lastName: ""
}
);
I was thinking this, but I wonder if there's a better way.
type TName = { firstName: string; lastName: string };
const [{ firstName, lastName }, setName] = useReducer(
(prev: TName, next: Partial<TName>) => ({ ...prev, ...next }),
{
firstName: "",
lastName: ""
}
);
type TName = { firstName: string; lastName: string };
const [{ firstName, lastName }, setName] = useReducer(
(prev: TName, next: Partial<TName>) => ({ ...prev, ...next }),
{
firstName: "",
lastName: ""
}
);
1 replies
TTCTheo's Typesafe Cult
Created by Samip Poudel on 11/3/2022 in #questions
TypeScript confusion
Can anyone explain why third-line errors but the fourth line works?
type First<T> = T extends any[] ? T[0] : never;

const myarr = [1, 2, 3]

type FirstItem = First<myarr>; // This errors saying you should pass type instead of value

type FirstItem1 = First<[1, 2, 3]> // This works even if we are passing value
type First<T> = T extends any[] ? T[0] : never;

const myarr = [1, 2, 3]

type FirstItem = First<myarr>; // This errors saying you should pass type instead of value

type FirstItem1 = First<[1, 2, 3]> // This works even if we are passing value
5 replies
TTCTheo's Typesafe Cult
Created by Samip Poudel on 10/26/2022 in #questions
SWC compiler allows const variable re-assignment
2 replies