Files
sweet/src/runtime/head.ts
T
Luca Casonato cbbf616a74 chore: version preact explicitly in import map (#258)
This allows users to control the `preact` version independently of fresh
itself.
2022-06-20 12:37:24 +02:00

23 lines
568 B
TypeScript

import { ComponentChildren, createContext } from "preact";
import { useContext } from "preact/hooks";
export interface HeadProps {
children: ComponentChildren;
}
export const HEAD_CONTEXT = createContext<ComponentChildren[]>([]);
export function Head(props: HeadProps) {
let context: ComponentChildren[];
try {
context = useContext(HEAD_CONTEXT);
} catch (err) {
throw new Error(
"<Head> component is not supported in the browser, or during suspense renders.",
{ cause: err },
);
}
context.push(props.children);
return null;
}