Grifn
Explore posts from serversTTCTheo's Typesafe Cult
•Created by Grifn on 10/25/2023 in #questions
Next server actions and REST API
Are server actions going to make REST APIs or tools like tRPC for Next client to server redundant? Or will they still have their place? We are starting a new project and we’re looking at using ts-rest so we can share schemas and validation from client-server-other APIs.
2 replies
TTCTheo's Typesafe Cult
•Created by Grifn on 7/12/2023 in #questions
tRPC, SSR, RSC/app directory
Is it possible to use tRPC when rendering a component on the server to get an initial value for a request before refetching on the client on mount? If not, what is the next best thing?
fetch
on the server and pass value to the client component using tRPC to set the initialValue on useQuery? Are there problems with that?
Does anyone have a current workflow in which they are successfully using tRPC with the app directory and able to SSR with data from tRPC useQuery?
Is there an alternative solution to using react-query or swr with fetch?12 replies
TTCTheo's Typesafe Cult
•Created by Grifn on 12/9/2022 in #questions
Testing with Typescript
When writing tests for a Typescript project, should functions still be written with fail conditions in mind so they can be tested properly? Or are those tests pointless because the project is using TS?
Example: Testing a
getFirstDayOfWeek
function takes a Date
as an argument. Of course if a string is provided, the function will fail when it tries to getDay()
on the string. Should I check if the date is an instanceof Date
and return undefined if not? This can then be tested by providing something other than a Date.
I don't know how other developers on the (large) team will interact with the code I'm writing and thinking I should add the fail condition code, but it means a lot of the other code that uses this getFirstDayOfWeek
function needs to suffer by expecting either a Date
or undefined
as a result of the function.
Or in this specific case, if a Date
isn't provided should I just use today's date and always return a Date
.2 replies