Skip to content

Commit 851eae4

Browse files
authored
Create useApi.js
1 parent e40536c commit 851eae4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

frontend/src/hooks/useApi.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { useState, useEffect } from "react";
2+
3+
export function useApi(endpoint) {
4+
const [data, setData] = useState(null);
5+
6+
useEffect(() => {
7+
fetch(`/api/${endpoint}`)
8+
.then((res) => res.json())
9+
.then(setData)
10+
.catch(console.error);
11+
}, [endpoint]);
12+
13+
return data;
14+
}

0 commit comments

Comments
 (0)