Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

612 B
Raw Blame
import { fetcher } from "@dub/utils";
import useSWR from "swr";
import useWorkspace from "./use-workspace";

export default function useDefaultDomains(opts: { search?: string } = {}) {
  const { id: workspaceId } = useWorkspace();

  const { data, error, mutate } = useSWR<string[]>(
    workspaceId &&
      `/api/domains/default?${new URLSearchParams({
        workspaceId,
        ...(opts.search && { search: opts.search }),
      }).toString()}`,
    fetcher,
    {
      dedupingInterval: 60000,
    },
  );

  return {
    defaultDomains: data,
    loading: !data && !error,
    mutate,
    error,
  };
}