synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
26 lines (25 loc) • 633 B
JavaScript
import { useQuery as r } from "@tanstack/react-query";
const s = async (t, e) => {
const n = t ? t.replace("https://doi.org/", "") : "", o = await fetch(
`https://citation.doi.org/format?doi=${n}&style=${e}&lang=en-US`,
{
headers: {
Accept: `text/x-${e}`
}
}
);
if (!o.ok)
throw new Error(
`Failed to fetch citation: ${o.status}: ${o.statusText}`
);
return await o.text();
}, i = (t, e, n) => r({
queryKey: ["citation", t, e],
queryFn: () => s(t, e),
enabled: !!t && !!e && n
});
export {
s as fetchCitation,
i as useCitation
};
//# sourceMappingURL=useCitation.js.map