slate/pages/_document.js

35 lines
760 B
JavaScript
Raw Normal View History

import Document, { Html, Head, Main, NextScript } from "next/document";
import { extractCritical } from "@emotion/server";
2020-02-19 09:30:47 +03:00
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 }}
/>
</>
),
};
2020-02-19 09:30:47 +03:00
}
render() {
return (
<Html>
<Head />
2020-02-19 09:30:47 +03:00
<body>
<Main />
<NextScript />
</body>
</Html>
2020-02-19 09:30:47 +03:00
);
}
}