Skip to content

Commit dc36eee

Browse files
committed
docs: examples using new useLoadingState
1 parent a8f40c6 commit dc36eee

File tree

3 files changed

+18
-88
lines changed

3 files changed

+18
-88
lines changed

.github/workflows/codeql.yml

Lines changed: 0 additions & 77 deletions
This file was deleted.

playground/src/App.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { usePage, Link, useQueryString, usePaths, useErrorPage, NotFoundRoute } from "../../src";
1+
import { Link, NotFoundRoute, Outlet, useErrorPage, usePaths, useQueryString } from "../../src";
22
import { router } from "./routes";
33
import { NotFound } from "./not-found";
44

55
function App() {
6-
const page = usePage();
76
const error = useErrorPage<NotFoundRoute>();
87
const queryString = useQueryString();
98
const paths = usePaths();
@@ -47,7 +46,9 @@ function App() {
4746
</nav>
4847
</header>
4948
<div className="w-full container max-w-lg mx-auto px-4 md:px-0">
50-
{page !== null ? <main className="page">{page}</main> : null}
49+
<main className="page">
50+
<Outlet />
51+
</main>
5152
<NotFound error={error} />
5253
</div>
5354
</div>

playground/src/pages/root.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ActionProps, createFormPath, Form, InferLoader, jsonResponse, LoaderProps, redirectResponse, useDataLoader } from "../../../src";
1+
import { ActionProps, createFormPath, Form, jsonResponse, LoaderProps, redirectResponse, useDataLoader, useLoadingState } from "../../../src";
22
import { useEffect, useState } from "react";
33
import { Input } from "../components/input";
44

@@ -10,9 +10,11 @@ export const actions = () => ({
1010
post: async (args: ActionProps<Route>) => {
1111
const url = new URL(args.request.url);
1212
const json = await args.request.json();
13+
console.log(args.request);
1314
url.searchParams.set("firstName", json.person.name);
1415
url.searchParams.set("lastName", json.person.surname);
1516
url.searchParams.set("date", json.person.birthday);
17+
await new Promise((res) => setTimeout(res, 3000));
1618
return redirectResponse(url.href);
1719
},
1820
});
@@ -34,6 +36,8 @@ export default function Root() {
3436
console.log("data loader", data?.qs);
3537
}, [data]);
3638

39+
const loading = useLoadingState();
40+
3741
return (
3842
<section className="flex flex-col gap-12">
3943
<h2 className="font-bold text-3xl">Form post action - json</h2>
@@ -43,13 +47,15 @@ export default function Root() {
4347
>
4448
Throw error
4549
</button>
46-
<Form encType="json" method="post" className="flex gap-8 items-end">
47-
<Input defaultValue={qs?.firstName} name={path("person.name")} placeholder="First Name" />
48-
<Input defaultValue={qs?.lastName} name={path("person.surname")} placeholder="Last Name" />
49-
<Input defaultValue={qs?.date} name={path("person.birthday")} type="date" placeholder="Birthday" />
50-
<button className="py-2 px-4 rounded bg-blue-500 text-white font-medium" type="submit">
51-
Submit
52-
</button>
50+
<Form encType="json" method="post">
51+
<fieldset className="flex gap-8 items-end disabled:opacity-40 disabled:bg-gray-400">
52+
<Input defaultValue={qs?.firstName} name={path("person.name")} placeholder="First Name" />
53+
<Input defaultValue={qs?.lastName} name={path("person.surname")} placeholder="Last Name" />
54+
<Input defaultValue={qs?.date} name={path("person.birthday")} type="date" placeholder="Birthday" />
55+
<button className="py-2 px-4 rounded bg-blue-500 text-white font-medium" type="submit">
56+
{loading ? "Saving..." : "Submit"}
57+
</button>
58+
</fieldset>
5359
</Form>
5460
</section>
5561
);

0 commit comments

Comments
 (0)