homepage/src/utils/proxy/use-widget-api.js
2023-04-05 22:45:27 -07:00

14 lines
453 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, mutate } = useSWR(formatProxyUrl(widget, ...options), config);
// make the data error the top-level error
return { data, error: data?.error ?? error, mutate }
}