mirror of
https://github.com/karl0ss/homepage.git
synced 2025-04-29 12:03:41 +01:00
18 lines
515 B
JavaScript
18 lines
515 B
JavaScript
import useSWR from "swr";
|
|
|
|
import { formatProxyUrl } from "./api-helpers";
|
|
|
|
export default function useWidgetAPI(widget, ...options) {
|
|
const config = {};
|
|
if (options && options[1]?.refreshInterval) {
|
|
config.refreshInterval = options[1].refreshInterval;
|
|
}
|
|
let url = formatProxyUrl(widget, ...options)
|
|
if (options[0] === "") {
|
|
url = null
|
|
}
|
|
const { data, error, mutate } = useSWR(url, config);
|
|
// make the data error the top-level error
|
|
return { data, error: data?.error ?? error, mutate }
|
|
}
|