homepage/src/utils/proxy/use-widget-api.js

14 lines
420 B
JavaScript
Raw Normal View History

2022-09-27 22:59:14 +03:00
import useSWR from "swr";
import { formatProxyUrl } from "./api-helpers";
export default function useWidgetAPI(widget, ...options) {
2022-11-07 09:24:15 -08:00
const config = {};
if (options?.refreshInterval) {
config.refreshInterval = options.refreshInterval;
}
const { data, error } = useSWR(formatProxyUrl(widget, ...options), config);
// make the data error the top-level error
return { data, error: data?.error ?? error }
2022-09-27 22:59:14 +03:00
}