27 lines
560 B
TypeScript
27 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(" ");
|
|
}
|