fix(striker-ui): override document to enable styled components

main
Tsu-ba-me 4 years ago
parent 4ad5640ab0
commit 256c732f8e
  1. 36
      striker-ui/pages/_document.tsx

@ -0,0 +1,36 @@
import Document, { DocumentContext, DocumentInitialProps } from 'next/document';
import { ServerStyleSheet } from 'styled-components';
class StyledDocument extends Document {
static async getInitialProps(
context: DocumentContext,
): Promise<DocumentInitialProps> {
const styleSheet = new ServerStyleSheet();
const originalRenderPage = context.renderPage;
try {
context.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) =>
// eslint-disable-next-line react/jsx-props-no-spreading
styleSheet.collectStyles(<App {...props} />),
});
const initialProps = await Document.getInitialProps(context);
return {
...initialProps,
styles: (
<>
{initialProps.styles}
{styleSheet.getStyleElement()}
</>
),
};
} finally {
styleSheet.seal();
}
}
}
export default StyledDocument;
Loading…
Cancel
Save