playroom
playroom copied to clipboard
Modify Head
It would be nice to have a way to include things in the head of the page.
For example here i need to include a company font icon hosted on an internal CDN. Something like storybook's preview-head.html would be perfect
There is a workaround in the meantime, by "abusing" framecomponent to append scripts/stylesheet in the head.
Example:
import * as React from 'react';
function useStylesheet(url: string) {
React.useEffect(() => {
const link = document.createElement('link');
link.href = url;
link.rel = 'stylesheet';
const head = document.getElementsByTagName('head')[0];
head.appendChild(link);
return function() {
head.removeChild(link);
};
}, [url]);
}
export default function PlayroomFrame(props: { children: React.ReactNode }) {
useStylesheet('https://mycdn/mystyle.css');
return <>{props.children}</>;
}