Skip to content

Commit b7ef54a

Browse files
authored
chore: use LoaderFunctionArgs and loaderData props (#135)
1 parent 9ecb876 commit b7ef54a

File tree

7 files changed

+27
-33
lines changed

7 files changed

+27
-33
lines changed

app/root.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { LoaderFunction, MetaFunction } from "react-router";
1+
import type { LoaderFunctionArgs, MetaFunction } from "react-router";
22
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from "react-router";
33

44
import "./styles/tailwind.css";
@@ -12,13 +12,11 @@ export const meta: MetaFunction = () => [
1212
},
1313
];
1414

15-
export const loader: LoaderFunction = async ({
16-
request,
17-
}: Parameters<LoaderFunction>[0]) => {
15+
export async function loader({ request }: LoaderFunctionArgs) {
1816
return {
1917
user: await getUser(request),
2018
};
21-
};
19+
}
2220

2321
export default function App() {
2422
return (

app/routes/__auth.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import { Outlet, useLoaderData, useLocation } from "react-router";
2-
1+
import type { Route } from "./+types/__auth";
2+
import { Outlet, useLocation, type LoaderFunctionArgs } from "react-router";
33
import { Login } from "#~/components/login";
44
import { isProd } from "#~/helpers/env.server";
55
import { getUser } from "#~/models/session.server";
66
import { useOptionalUser } from "#~/utils";
77

8-
export async function loader({ request }: { request: Request }) {
8+
export async function loader({ request }: LoaderFunctionArgs) {
99
return { user: await getUser(request), isProd: isProd() };
1010
}
1111

12-
export default function Auth() {
13-
const { isProd } = useLoaderData<typeof loader>();
12+
export default function Auth({ loaderData }: Route.ComponentProps) {
1413
const user = useOptionalUser();
1514
const location = useLocation();
1615

17-
if (isProd) {
16+
if (loaderData.isProd) {
1817
return <div>nope</div>;
1918
}
2019

app/routes/__auth/dashboard.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import type { LoaderFunction } from "react-router";
2-
import { data, useLoaderData, useNavigation } from "react-router";
1+
import type { Route } from "./+types/dashboard";
2+
import { data, type LoaderFunctionArgs, useNavigation } from "react-router";
33
import type { LabelHTMLAttributes, PropsWithChildren } from "react";
44
import { getTopParticipants } from "#~/models/activity.server";
55

6-
export const loader = async ({
7-
request,
8-
// context,
9-
// params,
10-
}: Parameters<LoaderFunction>[0]) => {
6+
export async function loader({ request }: LoaderFunctionArgs) {
117
// const user = await getUser(request);
128
const url = new URL(request.url);
139
const start = url.searchParams.get("start");
@@ -28,7 +24,7 @@ export const loader = async ({
2824
);
2925

3026
return output;
31-
};
27+
}
3228

3329
const Label = (props: LabelHTMLAttributes<Element>) => (
3430
<label {...props} className={`${props.className ?? ""} m-4`}>
@@ -65,9 +61,10 @@ const DataHeading = ({ children }: PropsWithChildren) => {
6561
);
6662
};
6763

68-
export default function DashboardPage() {
64+
export default function DashboardPage({
65+
loaderData: data,
66+
}: Route.ComponentProps) {
6967
const nav = useNavigation();
70-
const data = useLoaderData<typeof loader>();
7168

7269
if (nav.state === "loading") {
7370
return "loading…";

app/routes/auth.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ActionFunction, LoaderFunction } from "react-router";
1+
import type { ActionFunctionArgs, LoaderFunction } from "react-router";
22
import { redirect } from "react-router";
33

44
import { initOauthLogin } from "#~/models/session.server";
@@ -8,7 +8,7 @@ export const loader: LoaderFunction = async () => {
88
return redirect("/");
99
};
1010

11-
export const action: ActionFunction = async ({ request }) => {
11+
export async function action({ request }: ActionFunctionArgs) {
1212
// fetch user from db
1313
// if doesn't exist, create it with discord ID + email
1414
const form = await request.formData();
@@ -17,7 +17,7 @@ export const action: ActionFunction = async ({ request }) => {
1717
request,
1818
redirectTo: form.get("redirectTo")?.toString() ?? undefined,
1919
});
20-
};
20+
}
2121

2222
export default function LoginPage() {
2323
return (

app/routes/discord-oauth.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { redirect, type LoaderFunction } from "react-router";
1+
import { redirect, type LoaderFunctionArgs } from "react-router";
22
import { completeOauthLogin } from "#~/models/session.server";
33

4-
export const loader: LoaderFunction = async ({ request }) => {
4+
export async function loader({ request }: LoaderFunctionArgs) {
55
const url = new URL(request.url);
66
const code = url.searchParams.get("code");
77
const cookie = request.headers.get("Cookie");
@@ -19,4 +19,4 @@ export const loader: LoaderFunction = async ({ request }) => {
1919
cookie,
2020
url.searchParams.get("state") ?? undefined,
2121
);
22-
};
22+
}

app/routes/healthcheck.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// learn more: https://fly.io/docs/reference/configuration/#services-http_checks
2-
import type { LoaderFunction } from "react-router";
2+
import type { LoaderFunctionArgs } from "react-router";
33
import db from "#~/db.server";
44

5-
export const loader: LoaderFunction = async ({ request }) => {
5+
export async function loader({ request }: LoaderFunctionArgs) {
66
const host =
77
request.headers.get("X-Forwarded-Host") ?? request.headers.get("host");
88

@@ -22,4 +22,4 @@ export const loader: LoaderFunction = async ({ request }) => {
2222
console.log("healthcheck ❌", { error });
2323
return new Response("ERROR", { status: 500 });
2424
}
25-
};
25+
}

app/routes/logout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { ActionFunction } from "react-router";
1+
import type { ActionFunctionArgs } from "react-router";
22

33
import { logout } from "#~/models/session.server";
44

5-
export const action: ActionFunction = async ({ request }) => {
5+
export async function action({ request }: ActionFunctionArgs) {
66
return await logout(request);
7-
};
7+
}
88

99
export default function Logout() {
1010
return (

0 commit comments

Comments
 (0)