Last change
on this file since efaa053 was 07f4e8b, checked in by darsov2 <62809499+darsov2@…>, 8 months ago |
prefinal fixes
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | import axios from "../../axios";
|
---|
2 | import {useState, useEffect, useContext} from 'react';
|
---|
3 |
|
---|
4 | const 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.get(uurl, {maxRedirects: 0}).then((res) => {
|
---|
14 | console.log(res);
|
---|
15 | // if(res.request.responseURL.includes('8080'))
|
---|
16 | // {
|
---|
17 | // window.location.href = "/login"
|
---|
18 | // }
|
---|
19 | setData(res.data);
|
---|
20 | }).catch((error) => {
|
---|
21 | console.log(error)
|
---|
22 | // window.location.href = '/error'
|
---|
23 | })
|
---|
24 | .finally(() => {
|
---|
25 | setIsLoading(false);
|
---|
26 | });
|
---|
27 | };
|
---|
28 |
|
---|
29 | useEffect(() => {
|
---|
30 | setIsLoading(true);
|
---|
31 | getData(url);
|
---|
32 | }, [dep, url, changed]);
|
---|
33 |
|
---|
34 | return {
|
---|
35 | data,
|
---|
36 | setData,
|
---|
37 | isLoading,
|
---|
38 | getData,
|
---|
39 | setChanged
|
---|
40 | };
|
---|
41 | };
|
---|
42 |
|
---|
43 |
|
---|
44 | export default useGet; |
---|
Note:
See
TracBrowser
for help on using the repository browser.