mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-07 14:18:47 +00:00
13 lines
437 B
JavaScript
13 lines
437 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;
|
|
}
|
|
const { data, error } = useSWR(formatProxyUrl(widget, ...options), config);
|
|
// make the data error the top-level error
|
|
return { data, error: data?.error ?? error }
|
|
}
|