mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-16 09:05:57 -07:00
18 lines
559 B
JavaScript
18 lines
559 B
JavaScript
import useSWR from "swr";
|
|
|
|
import { formatProxyUrl } from "./api-helpers";
|
|
|
|
export default function useWidgetAPI(widget, endpoint, queryParams, swrConfig = {}) {
|
|
const config = { ...swrConfig };
|
|
if (queryParams?.refreshInterval) {
|
|
config.refreshInterval = queryParams.refreshInterval;
|
|
}
|
|
let url = formatProxyUrl(widget, endpoint, queryParams);
|
|
if (endpoint === "") {
|
|
url = null;
|
|
}
|
|
const { data, error, mutate } = useSWR(url, config);
|
|
// make the data error the top-level error
|
|
return { data, error: data?.error ?? error, mutate };
|
|
}
|