@coinmeca/ui
Version:
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
27 lines • 1.02 kB
JSX
"use client";
import React, { useState } from "react";
import { useServerInsertedHTML } from "next/navigation";
import { ServerStyleSheet, StyleSheetManager } from "styled-components";
import Global from "./Global";
export function Configure({ children }) {
// Only create stylesheet once with lazy initial state
// x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
const [styleSheet] = useState(() => new ServerStyleSheet());
useServerInsertedHTML(() => {
const styles = styleSheet.getStyleElement();
styleSheet.instance.clearTag();
return <>{styles}</>;
});
if (typeof window !== "undefined")
return <>{children}</>;
return <StyleSheetManager sheet={styleSheet.instance}>{children}</StyleSheetManager>;
}
export default function Initialize({ children }) {
return (<Configure>
<>
<Global />
{children}
</>
</Configure>);
}
//# sourceMappingURL=Initialize.jsx.map