UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

43 lines (42 loc) 1.1 kB
import { useQueryClient as l, useMutation as h } from "@tanstack/react-query"; function d({ shortIoPublicApiKey: n, domain: i, onSuccess: a, onError: c }) { const o = l(), e = ["shortUrl", typeof window < "u" ? window.location.href : ""], r = o.getQueryData(e); return h({ mutationFn: async () => { if (r) return r; if (n) { const t = await fetch("https://api.short.io/links/public", { method: "POST", headers: { Authorization: n, "Content-Type": "application/json", Accept: "application/json" }, body: JSON.stringify({ originalURL: window.location.href, domain: i }) }); if (!t.ok) { const u = await t.text(); throw new Error(u); } const s = (await t.json()).shortURL; return o.setQueryData(e, s), s; } else return window.location.href; }, onSuccess: a, onError: c }); } export { d as useCreateShortUrl }; //# sourceMappingURL=useCreateShortUrl.js.map