Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
clean: remove lots of useless code from the nextjs template
Browse files Browse the repository at this point in the history
  • Loading branch information
OrJDev committed Apr 30, 2023
1 parent a6d2e26 commit fa3e1ed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 81 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-mails-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-prpc-app': patch
---

clean: remove lots of useless code from the nextjs template
53 changes: 10 additions & 43 deletions examples/nextjs/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,61 +1,28 @@
import { handle$ } from "@prpc/react";
import { middleware$, query$, response$ } from "@prpc/react";
import { GetServerSideProps, type NextPage } from "next";
import { query$, response$ } from "@prpc/react";
import { type NextPage } from "next";
import { z } from "zod";
import { queryClient } from "./_app";

const testMw = middleware$(async ({ request$ }) => {
const ua = request$.headers.get("user-agent");
console.log({ ua });
return {
ua,
};
});

const myQuery = query$({
queryFn: async ({ payload }) => {
await new Promise((resolve) => setTimeout(resolve, 3000));
return response$(payload.num / 2);
},
key: "testQuery",
middlewares: [testMw],
schema: z.object({
num: z.number(),
}),
});

export const getServerSideProps: GetServerSideProps = async (ctx) => {
const dehydarated = await handle$({
queryFn: myQuery,
ctx,
payload: {
num: 2,
},
queryClient,
});
return {
props: dehydarated,
};
};

const Home: NextPage = () => {
const { data } = myQuery(
{
num: "d",
},
{
retry: false,
onError: (err) => {
console.log("err", err.cause);
console.log(err.isZodError());
},
}
);
const { data, isLoading } = myQuery({
num: 2,
});
return (
<main className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#2e026d] to-[#15162c]">
<div className="text-5xl text-white">
query: {JSON.stringify(data, null, 2)}
</div>
{isLoading ? (
<div className="text-5xl text-white">Loading...</div>
) : data ? (
<div className="text-5xl text-white">query: {data}</div>
) : null}
</main>
);
};
Expand Down
48 changes: 10 additions & 38 deletions packages/create/templates/NextJS/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,28 @@
import { handle$ } from "@prpc/react";
import { middleware$, query$, response$ } from "@prpc/react";
import { type GetServerSideProps, type NextPage } from "next";
import { query$, response$ } from "@prpc/react";
import { type NextPage } from "next";
import { z } from "zod";
import { queryClient } from "./_app";

const testMw = middleware$(({ request$ }) => {
const ua = request$.headers.get("user-agent");
console.log({ ua });
return {
ua,
};
});

const myQuery = query$({
queryFn: async ({ payload }) => {
await new Promise((resolve) => setTimeout(resolve, 3000));
return response$(payload.num / 2);
},
key: "testQuery",
middlewares: [testMw],
schema: z.object({
num: z.number(),
}),
});

export const getServerSideProps: GetServerSideProps = async (ctx) => {
const dehydarated = await handle$({
queryFn: myQuery,
ctx,
payload: {
num: 2,
},
queryClient,
});
return {
props: dehydarated,
};
};

const Home: NextPage = () => {
const { data } = myQuery(
{
num: 2,
},
{
refetchOnMount: false,
refetchOnWindowFocus: false,
}
);
const { data, isLoading } = myQuery({
num: 2,
});
return (
<main className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#2e026d] to-[#15162c]">
<div className="text-5xl text-white">query: {data}</div>
{isLoading ? (
<div className="text-5xl text-white">Loading...</div>
) : data ? (
<div className="text-5xl text-white">query: {data}</div>
) : null}
</main>
);
};
Expand Down

1 comment on commit fa3e1ed

@vercel
Copy link

@vercel vercel bot commented on fa3e1ed Apr 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

prpc-docs – ./

prpc-docs.vercel.app
prpc.vercel.app
prpc-docs-orjdev.vercel.app
prpc-docs-git-main-orjdev.vercel.app

Please sign in to comment.