21 lines
553 B
TypeScript
21 lines
553 B
TypeScript
import {
|
|
readCachedPaymentLink,
|
|
writeCachedPaymentLink,
|
|
} from '../utils/paymentLinkCache';
|
|
|
|
export function usePaymentLinkCache() {
|
|
const lastLink = useState<string | null>('payment-link-cache', () => null);
|
|
|
|
if (import.meta.client && lastLink.value === null) {
|
|
lastLink.value = readCachedPaymentLink(window.localStorage);
|
|
}
|
|
|
|
function rememberLink(link: string) {
|
|
if (!import.meta.client || !link) return;
|
|
lastLink.value = link;
|
|
writeCachedPaymentLink(window.localStorage, link);
|
|
}
|
|
|
|
return { lastLink, rememberLink };
|
|
}
|