-
Notifications
You must be signed in to change notification settings - Fork 139
/
CreateNote.tsx
64 lines (54 loc) · 1.27 KB
/
CreateNote.tsx
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use client';
// export default function Test() {
// return (
// <div>
// <h1>Create Note</h1>
// </div>
// );
// }
import { useState } from 'react';
import { useRouter } from 'next/navigation';
export default function CreateNote() {
const [title, setTitle] = useState('');
const [content, setContent] = useState('');
const router = useRouter();
const create = async() => {
// const db = new PocketBase('http://127.0.0.1:8090');
// await db.records.create('notes', {
// title,
// content,
// });
await fetch('http://127.0.0.1:8090/api/collections/notes/records', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
title,
content,
}),
});
setContent('');
setTitle('');
router.refresh();
}
return (
<form onSubmit={create}>
<h3>Create a new Note</h3>
<input
type="text"
placeholder="Title"
value={title}
onChange={(e) => setTitle(e.target.value)}
/>
<textarea
placeholder="Content"
value={content}
onChange={(e) => setContent(e.target.value)}
/>
<button type="submit">
Create note
</button>
</form>
);
}