This commit is contained in:
Jan Prochazka
2019-12-25 22:44:39 +01:00
parent b936cb9e25
commit c203758fd8
14 changed files with 19 additions and 6 deletions

15
src/ui/useFetch.js Normal file
View 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;
}