slate/pages/_document.js
2020-09-09 02:16:01 -07:00

35 lines
760 B
JavaScript

import Document, { Html, Head, Main, NextScript } from "next/document";
import { extractCritical } from "@emotion/server";
export default class MyDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx);
const styles = extractCritical(initialProps.html);
return {
...initialProps,
styles: (
<>
{initialProps.styles}
<style
data-emotion-css={styles.ids.join(" ")}
dangerouslySetInnerHTML={{ __html: styles.css }}
/>
</>
),
};
}
render() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}