pogadev
pogadev
Explore posts from servers
TTCTheo's Typesafe Cult
Created by pogadev on 6/13/2023 in #questions
Anyone used the `Etag` response header inside a Next.js Application?
I am using a getServerSideProps that renders some HTML on the server but everytime I make a request to my Next.js Application a new Etag is generated even tho' the contents are the same. I'm pretty sure it has something to do with getServerSideProps and I would like to keep it that way because I need some send some responses back in case of a business logic is met
1 replies
TTCTheo's Typesafe Cult
Created by pogadev on 9/27/2022 in #questions
tRPC app with SSR true, getStaticProps or getServerSideProps
Hi all, I've been trying to figure out what is the best way to fetch queries on my website that I'm building with T3 stack. Long story short: I'm creating a website that will be like a portfolio and an online resume. I have a page called /projects and I'm trying to fetch all the projects on the server, so all the projects can be available when the users arrives on the page. I've been reading a lot of stuff lately about SSR and which methods to use to fetch data, either getServerSideProps or getStaticProps. On top of this, I know that tRPC configuration accepts a ssr: true | false property. I'm kind of confused right now because every time I'm using my app with ssr: true when I look at the network requests and I see my projects page request, it comes back as an HTML page, fully rendered, meaning. that it was fetched on the server, which is great. Also, with ssr: true I'm fetching my projects like this:
function ProjectsPage() {
const {data: projects} = trpc.useQuery(['projects.all-projects'])

return (
<>
{projects && <ProjectsList projects={projects}/>}
</>
)
}

export default ProjectsPage
function ProjectsPage() {
const {data: projects} = trpc.useQuery(['projects.all-projects'])

return (
<>
{projects && <ProjectsList projects={projects}/>}
</>
)
}

export default ProjectsPage
The confusion now is why should I fetch data in getStaticProps or getServerSideProps, something like this (taken from tRPC documentation):
export async function getStaticProps(
context: GetStaticPropsContext<{ id: string }>,
) {
const ssg = await createSSGHelpers({
router: appRouter,
ctx: {},
transformer: superjson, // optional - adds superjson serialization
});
...
}
export async function getStaticProps(
context: GetStaticPropsContext<{ id: string }>,
) {
const ssg = await createSSGHelpers({
router: appRouter,
ctx: {},
transformer: superjson, // optional - adds superjson serialization
});
...
}
and just pass the data as props to my ProjectsPage route. As you can see, I can also fetch using this approach, or even prefetch data which is even more confusing...And if I fetch data in getStaticProps or getServerSideProps, should I configure my tRPC using the ssr boolean as well? I think I'm missing a good explanation about all these tools and I'm pretty sure it can be useful for others. I'd like to discuss this with you all.
11 replies
TTCTheo's Typesafe Cult
Created by pogadev on 9/24/2022 in #questions
PUT request with tRPC
Hi everyone! First of all, I tried to find an answer to my question but I couldn’t find one. I’m trying to update an entity in my database using tRPC stack. For example, I want to edit some of my posts on my website and update their title. Everything works fine but instead of a PUT request, I see a POST request in my network tab. How can I tell to my tRPC API to send a PUT request instead of a POST request? Much appreciated!! Thank you in advance
32 replies
TTCTheo's Typesafe Cult
Created by pogadev on 9/22/2022 in #questions
PRIMARY KEY in supabase DB
Hi everyone! I’m creating a full stack app with tRPC and I’ve connected Prisma to a supabase postgresql DB. Everything works fine but when I try to delete columns I have a error saying that I need a PRIMAY KEY. Can anyone please explain to me why I need that primary key in order to delete /edit my data in DB? 🙏 thanks
11 replies