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

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

prototype

  • Property mode set to 100644
File size: 926 bytes
RevLine 
[e9b4ba9]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).then((res) => {
15 setData(res.data);
16 }).catch((err) => {
17 console.log(err)
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.