source: frontend/src/Components/Hooks/useGet.js@ ac19a0c

Last change on this file since ac19a0c was ac19a0c, checked in by darsov2 <62809499+darsov2@…>, 6 months ago

authContext impl, admin panel impl, search bar fixes, reservations listings impl

  • Property mode set to 100644
File size: 945 bytes
Line 
1import axios from "../../axios";
2import { useState, useEffect, useContext } from 'react';
3
4const useGet = (url, dep) => {
5
6 console.log(url)
7 const [data, setData] = useState(null);
8 const [isLoading, setIsLoading] = useState(true);
9 const [changed, setChanged] = useState(0)
10 const getData = async (uurl) => {
11 console.log(localStorage.getItem("sessionId"))
12 console.log("url od get " + uurl)
13 await axios.
14 get(uurl, {maxRedirects: 0}).then((res) => {
15 setData(res.data);
16 }).catch((error) => {
17 console.log(error)
18 })
19 .finally(() => {
20 setIsLoading(false);
21 });
22 };
23
24 useEffect(() => {
25 setIsLoading(true);
26 getData(url);
27 }, [dep, url, changed]);
28
29 return {
30 data,
31 setData,
32 isLoading,
33 getData,
34 setChanged
35 };
36};
37
38
39export default useGet;
Note: See TracBrowser for help on using the repository browser.