tutu/src/platform/DocumentTitle.tsx
thislight 1c8a3f0bbb
All checks were successful
/ depoly (push) Successful in 1m22s
remove utils
* add ~platform/DocumentTitle
* add titles for some pages
2025-01-02 22:43:37 +08:00

22 lines
512 B
TypeScript

import { children, createRenderEffect, onCleanup, type JSX } from "solid-js";
/**
* Document title.
*
* The `children` must be plain text.
*/
export default function (props: { children?: JSX.Element }) {
let otitle: string | undefined;
createRenderEffect(() => (otitle = document.title));
const title = children(() => props.children);
createRenderEffect(
() => (document.title = (title.toArray() as string[]).join("")),
);
onCleanup(() => (document.title = otitle!));
return <></>;
}