import { h } from 'preact';
import { baseUrl } from './baseUrl';
import useSWR, { SWRConfig } from 'swr';
import { WsProvider } from './ws';
import axios from 'axios';
axios.defaults.baseURL = `${baseUrl}api/`;
export function ApiProvider({ children, options }) {
return (
axios.get(path, { params }).then((res) => res.data),
...options,
}}
>
{children}
);
}
function WsWithConfig({ children }) {
const { data } = useSWR('config');
return data ? {children} : children;
}
export function useApiHost() {
return baseUrl;
}