webamp/js/components/Css.tsx
Jordan Eldredge 7bd8c702ac Make the Skin component use hooks and type it
This also abstracts some generic utility components
2019-12-23 17:06:36 -08:00

23 lines
502 B
TypeScript

import { createPortal } from "react-dom";
import { useMemo, useLayoutEffect } from "react";
type Props = {
children: string;
id: string;
};
export default function Css({ children, id }: Props) {
const style = useMemo(() => {
const s = document.createElement("style");
s.type = "text/css";
s.id = id;
return s;
}, [id]);
useLayoutEffect(() => {
document.head.appendChild(style);
return () => style.remove();
}, [style]);
return createPortal(children, style);
}