Files
dbgate/packages/web/src/utility/useFetch.ts
Jan Prochazka d5ebea3764 files widget
2021-03-11 09:42:14 +01:00

22 lines
462 B
TypeScript

import _ from 'lodash';
import axiosInstance from './axiosInstance';
import { writable } from 'svelte/store';
export default function useFetch({ url, data = undefined, params = undefined, defaultValue = undefined, ...config }) {
const result = writable(defaultValue);
axiosInstance
.request({
method: 'get',
params,
url,
data,
...config,
})
.then(resp => {
result.set(resp.data);
});
return result;
}