|
| 1 | +import type { ActionArgs } from "@remix-run/node"; |
| 2 | +import { redirect, type LoaderArgs, defer } from "@remix-run/node"; |
| 3 | +import type { V2_MetaFunction } from "@remix-run/node"; |
| 4 | +import { Link, useFetcher, useSubmit } from "@remix-run/react"; |
| 5 | +import { EmbeddedDevTools } from "remix-development-tools"; |
| 6 | + |
| 7 | +export const meta: V2_MetaFunction = () => { |
| 8 | + return [ |
| 9 | + { title: "New Remix App" }, |
| 10 | + { name: "description", content: "Welcome to Remix!" }, |
| 11 | + ]; |
| 12 | +}; |
| 13 | + |
| 14 | +export const loader = async ({ request }: LoaderArgs) => { |
| 15 | + const test = new Promise((resolve) => { |
| 16 | + setTimeout(() => { |
| 17 | + resolve("test"); |
| 18 | + }, 1000); |
| 19 | + }) |
| 20 | + return defer({ message: "Hello World!", test }); |
| 21 | +}; |
| 22 | + |
| 23 | +export const action = async ({ request }: ActionArgs) => { |
| 24 | + return redirect("/login"); |
| 25 | +}; |
| 26 | + |
| 27 | +export default function Index() { |
| 28 | + const lFetcher = useFetcher(); |
| 29 | + const pFetcher = useFetcher(); |
| 30 | + const submit = useSubmit(); |
| 31 | + const data = new FormData(); |
| 32 | + data.append("test", "test"); |
| 33 | + return ( |
| 34 | + <div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}> |
| 35 | + <h1>Welcome to Remix</h1> |
| 36 | + <button |
| 37 | + onClick={() => lFetcher.submit(null, { method: "get", action: "/" })} |
| 38 | + > |
| 39 | + FETCHER Loader |
| 40 | + </button> |
| 41 | + <button |
| 42 | + onClick={() => pFetcher.submit(data, { method: "POST", action: "/" })} |
| 43 | + > |
| 44 | + FETCHER Action |
| 45 | + </button> |
| 46 | + <button onClick={() => submit(null, { method: "POST", action: "/" })}> |
| 47 | + SUBMIT Action |
| 48 | + </button> |
| 49 | + <button onClick={() => submit(data, { method: "PATCH", action: "/" })}> |
| 50 | + SUBMIT Action PATCH |
| 51 | + </button> |
| 52 | + <button onClick={() => submit(null, { method: "DELETE", action: "/" })}> |
| 53 | + SUBMIT Action DELETE |
| 54 | + </button> |
| 55 | + <button onClick={() => submit(null, { method: "PUT", action: "/" })}> |
| 56 | + SUBMIT Action PUT |
| 57 | + </button> |
| 58 | + <div style={{ height: 400, overflowY: "auto", width: 1700 }}> |
| 59 | + <EmbeddedDevTools className="!h-[400px] !overflow-y-auto" mainPanelClassName="w-40" /> |
| 60 | + </div> |
| 61 | + <Link to="/login">Login</Link> |
| 62 | + <ul> |
| 63 | + <li> |
| 64 | + <a |
| 65 | + target="_blank" |
| 66 | + href="https://remix.run/tutorials/blog" |
| 67 | + rel="noreferrer" |
| 68 | + > |
| 69 | + 15m Quickstart Blog Tutorial |
| 70 | + </a> |
| 71 | + </li> |
| 72 | + <li> |
| 73 | + <a |
| 74 | + target="_blank" |
| 75 | + href="https://remix.run/tutorials/jokes" |
| 76 | + rel="noreferrer" |
| 77 | + > |
| 78 | + Deep Dive Jokes App Tutorial |
| 79 | + </a> |
| 80 | + </li> |
| 81 | + <li> |
| 82 | + <a target="_blank" href="https://remix.run/docs" rel="noreferrer"> |
| 83 | + Remix Docs |
| 84 | + </a> |
| 85 | + </li> |
| 86 | + </ul> |
| 87 | + </div> |
| 88 | + ); |
| 89 | +} |
0 commit comments