|
| 1 | +import type { ActionFunctionArgs } from "@remix-run/node"; |
| 2 | +import { json, type LoaderFunctionArgs } from "@remix-run/node"; |
| 3 | +import type { MetaFunction } from "@remix-run/node"; |
| 4 | +import { Link, useFetcher, useLoaderData, useSubmit } from "@remix-run/react"; |
| 5 | + |
| 6 | +export const meta: MetaFunction = () => { |
| 7 | + return [ |
| 8 | + { title: "New Remix App" }, |
| 9 | + { name: "description", content: "Welcome to Remix!" }, |
| 10 | + ]; |
| 11 | +}; |
| 12 | + |
| 13 | +export const loader = async ({ request }: LoaderFunctionArgs) => { |
| 14 | + await new Promise((resolve) => setTimeout(resolve, 2000)); |
| 15 | + return json({ |
| 16 | + should: "work", |
| 17 | + with: { |
| 18 | + nested: { |
| 19 | + objects: { |
| 20 | + really: { |
| 21 | + deep: "inside", |
| 22 | + array: [ |
| 23 | + "this", |
| 24 | + "is", |
| 25 | + "a", |
| 26 | + "really", |
| 27 | + "long", |
| 28 | + "array", |
| 29 | + "that", |
| 30 | + "should", |
| 31 | + "be", |
| 32 | + "truncated", |
| 33 | + ], |
| 34 | + }, |
| 35 | + }, |
| 36 | + }, |
| 37 | + }, |
| 38 | + }, { headers: { "Set-Cookie": "test=1; Path=/; HttpOnly; Secure", "Cache-Control": "max-age=20"}}); |
| 39 | +}; |
| 40 | + |
| 41 | +export const action = async ({ request }: ActionFunctionArgs) => { |
| 42 | + return new Response(JSON.stringify({ test: "died" })); |
| 43 | +}; |
| 44 | + |
| 45 | +export default function IndexRoute() { |
| 46 | + const string = useLoaderData<typeof loader>(); |
| 47 | + const lFetcher = useFetcher(); |
| 48 | + const lFetcher2 = useFetcher(); |
| 49 | + const pFetcher = useFetcher(); |
| 50 | + const submit = useSubmit(); |
| 51 | + const data = new FormData(); |
| 52 | + data.append("test", "test"); |
| 53 | + return ( |
| 54 | + <div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}> |
| 55 | + <h1>Welcome to Remix 5</h1> |
| 56 | + <button |
| 57 | + onClick={() => |
| 58 | + lFetcher.submit(null, { method: "GET", action: "/tests/3/edit/new" }) |
| 59 | + } |
| 60 | + > |
| 61 | + FETCHER Loader |
| 62 | + </button>{" "} |
| 63 | + <button |
| 64 | + onClick={() => |
| 65 | + lFetcher2.submit(null, { method: "GET", action: "/tests/3/edit/new" }) |
| 66 | + } |
| 67 | + > |
| 68 | + FETCHER 2 Loader |
| 69 | + </button> |
| 70 | + <button |
| 71 | + onClick={() => |
| 72 | + pFetcher.submit(null, { method: "POST", action: "/tests/3/edit/new" }) |
| 73 | + } |
| 74 | + > |
| 75 | + FETCHER Action |
| 76 | + </button> |
| 77 | + <button |
| 78 | + onClick={() => { |
| 79 | + submit(data, { method: "POST", action: "/tests/3/edit/new/5/5" }); |
| 80 | + }} |
| 81 | + > |
| 82 | + SUBMIT Action test |
| 83 | + </button> |
| 84 | + <button |
| 85 | + onClick={() => |
| 86 | + submit(data, { method: "PATCH", action: "/tests/3/edit/new" }) |
| 87 | + } |
| 88 | + > |
| 89 | + SUBMIT Action PATCH |
| 90 | + </button> |
| 91 | + <button |
| 92 | + onClick={() => |
| 93 | + submit(null, { method: "DELETE", action: "/tests/3/edit/new" }) |
| 94 | + } |
| 95 | + > |
| 96 | + SUBMIT Action DELETE |
| 97 | + </button> |
| 98 | + <button |
| 99 | + onClick={() => |
| 100 | + submit(null, { method: "PUT", action: "/tests/3/edit/new" }) |
| 101 | + } |
| 102 | + > |
| 103 | + SUBMIT Action PUT |
| 104 | + </button> |
| 105 | + <Link to="/login">Login</Link> |
| 106 | + <ul> |
| 107 | + <li> |
| 108 | + <a |
| 109 | + target="_blank" |
| 110 | + href="https://remix.run/tutorials/blog" |
| 111 | + rel="noreferrer" |
| 112 | + > |
| 113 | + 15m Quickstart Blog Tutorial |
| 114 | + </a> |
| 115 | + </li> |
| 116 | + <li> |
| 117 | + <a |
| 118 | + target="_blank" |
| 119 | + href="https://remix.run/tutorials/jokes" |
| 120 | + rel="noreferrer" |
| 121 | + > |
| 122 | + Deep Dive Jokes App Tutorial |
| 123 | + </a> |
| 124 | + </li> |
| 125 | + <li> |
| 126 | + <a target="_blank" href="https://remix.run/docs" rel="noreferrer"> |
| 127 | + Remix Docs |
| 128 | + </a> |
| 129 | + </li> |
| 130 | + </ul> |
| 131 | + </div> |
| 132 | + ); |
| 133 | +} |
0 commit comments