You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
14 lines
453 B
14 lines
453 B
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 }
|
|
}
|