tutu/src/utils.tsx

27 lines
550 B
TypeScript
Raw Normal View History

2024-07-14 12:28:44 +00:00
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(' ')
}