tutu/src/utils.tsx
2024-07-14 20:28:44 +08:00

27 lines
550 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(' ')
}