source: frontend/src/Components/Hooks/useGet.js@ 5528b99

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

revert

  • Property mode set to 100644
File size: 1.4 KB
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<<<<<<< HEAD
14 await axios.get(uurl, {maxRedirects: 0}).then((res) => {
15 console.log(res);
16 // if(res.request.responseURL.includes('8080'))
17 // {
18 // window.location.href = "/login"
19 // }
20 setData(res.data);
21 }).catch((error) => {
22 console.log(error)
23 // window.location.href = '/error'
24 })
25=======
26 await axios.
27 get(uurl).then((res) => {
28 setData(res.data);
29 }).catch((err) => {
30 console.log(err)
31 })
32>>>>>>> parent of ac19a0c (authContext impl, admin panel impl, search bar fixes, reservations listings impl)
33 .finally(() => {
34 setIsLoading(false);
35 });
36 };
37
38 useEffect(() => {
39 setIsLoading(true);
40 getData(url);
41 }, [dep, url, changed]);
42
43 return {
44 data,
45 setData,
46 isLoading,
47 getData,
48 setChanged
49 };
50};
51
52
53export default useGet;
Note: See TracBrowser for help on using the repository browser.