mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 16:36:00 +00:00
refactor
This commit is contained in:
15
web/src/useFetch.js
Normal file
15
web/src/useFetch.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
import axios from 'axios'
|
||||
|
||||
export default function useFetch(url, defValue) {
|
||||
const [value, setValue] = React.useState(defValue);
|
||||
|
||||
async function loadValue() {
|
||||
setValue(await axios.get(url));
|
||||
}
|
||||
React.useEffect(() => {
|
||||
loadValue();
|
||||
}, [url]);
|
||||
|
||||
return value;
|
||||
}
|
||||
Reference in New Issue
Block a user