tutu/src/utils.tsx
2024-08-05 15:33:00 +08:00

26 lines
560 B
TypeScript

import { createRenderEffect, createSignal, onCleanup } from "solid-js";
export function useDocumentTitle(newTitle?: string) {
const capturedTitle = document.title;
const [title, setTitle] = createSignal(newTitle ?? capturedTitle);
createRenderEffect(() => {
document.title = title();
});
onCleanup(() => {
document.title = capturedTitle;
});
return setTitle;
}
export function mergeClass(c1: string | undefined, c2: string | undefined) {
if (!c1) {
return c2;
}
if (!c2) {
return c1;
}
return [c1, c2].join(" ");
}