mongoosedbcc 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,15 +4,18 @@ export default function App() {
4
4
  const [books, setBooks] = useState([]);
5
5
  const [title, setTitle] = useState('');
6
6
 
7
- // fetch books
7
+ const load = async () => {
8
+ const res = await fetch('/api/books');
9
+ setBooks(await res.json());
10
+ };
11
+
8
12
  useEffect(() => {
9
- fetch('/api/books')
10
- .then(res => res.json())
11
- .then(setBooks);
13
+ load();
12
14
  }, []);
13
15
 
14
- // add
15
16
  const add = async () => {
17
+ if (!title) return;
18
+
16
19
  await fetch('/api/books', {
17
20
  method: 'POST',
18
21
  headers: { 'Content-Type': 'application/json' },
@@ -20,21 +23,22 @@ export default function App() {
20
23
  });
21
24
 
22
25
  setTitle('');
23
- const res = await fetch('/api/books');
24
- setBooks(await res.json());
26
+ load(); // simpler refresh
25
27
  };
26
28
 
27
- // delete
28
29
  const del = async (id) => {
29
30
  await fetch('/api/books/' + id, { method: 'DELETE' });
30
- setBooks(books.filter(b => b._id !== id));
31
+ load(); // simpler than filter
31
32
  };
32
33
 
33
34
  return (
34
35
  <div>
35
36
  <h2>Library</h2>
36
37
 
37
- <input value={title} onChange={e => setTitle(e.target.value)} />
38
+ <input
39
+ value={title}
40
+ onChange={e => setTitle(e.target.value)}
41
+ />
38
42
  <button onClick={add}>Add</button>
39
43
 
40
44
  <ul>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongoosedbcc",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "install-all": "cd library-backend && npm install && cd ../library-frontend && npm install",