From 0f6c8f60860fd32a631e0f06620692bc41bac47f Mon Sep 17 00:00:00 2001 From: Jan Haase <105806818+cheminfolab@users.noreply.github.com> Date: Sat, 6 Apr 2024 11:46:58 +0200 Subject: [PATCH] I don't remember what I did here... --- frontend/src/context/ChemContext.js | 21 +++++++++++++++++++++ frontend/src/utils/useAxios2.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 frontend/src/context/ChemContext.js create mode 100644 frontend/src/utils/useAxios2.js diff --git a/frontend/src/context/ChemContext.js b/frontend/src/context/ChemContext.js new file mode 100644 index 0000000..c9066a2 --- /dev/null +++ b/frontend/src/context/ChemContext.js @@ -0,0 +1,21 @@ +import {createContext} from "@types/react"; + +const ChemContext = createContext({}) +export default ChemContext + +export const ChemProvider = ({children}) => { + + let getContainerList + let getContainer + + let contextData = { + // ContainerList:ContainerList, + // Container:Container, + // show:show // in context or on table page? + } + return( + + {/*{loading ? null : children}*/} + + ) +} \ No newline at end of file diff --git a/frontend/src/utils/useAxios2.js b/frontend/src/utils/useAxios2.js new file mode 100644 index 0000000..1509e4c --- /dev/null +++ b/frontend/src/utils/useAxios2.js @@ -0,0 +1,29 @@ +import { useState, useEffect } from 'react'; +import axios from 'axios'; + +axios.defaults.baseURL = 'https://jsonplaceholder.typicode.com'; + +const useAxios2 = (params, authentication=false) => { + const [response, setResponse] = useState(undefined); + const [error, setError] = useState(''); + const [loading, setLoading] = useState(true); + + const fetchData = async params => { + try { + const result = await axios.request(params); + setResponse(result.data); + } catch( error ) { + setError(error); + } finally { + setLoading(false); + } + }; + + useEffect(() => { + fetchData(params); + }, []); // execute once only + + return { response, error, loading }; +}; + +export default useAxios2 \ No newline at end of file