forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote.jsx
More file actions
26 lines (23 loc) · 664 Bytes
/
note.jsx
File metadata and controls
26 lines (23 loc) · 664 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { useLoaderData, Form, redirect } from "react-router-dom";
import { deleteNote, getNote } from "../notes";
export default function Note() {
const note = useLoaderData();
return (
<div>
<h2>{note.title}</h2>
<div>{note.content}</div>
<Form method="post" style={{ marginTop: "2rem" }}>
<button type="submit">Delete</button>
</Form>
</div>
);
}
export async function loader({ params }) {
const note = await getNote(params.noteId);
if (!note) throw new Response("", { status: 404 });
return note;
}
export async function action({ params }) {
await deleteNote(params.noteId);
return redirect("/new");
}