mirror of
https://github.com/morten-olsen/morten-olsen.github.io.git
synced 2026-02-08 01:46:28 +01:00
Server side render
This commit is contained in:
32
pages/_document.tsx
Normal file
32
pages/_document.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import Document from 'next/document';
|
||||
import { ServerStyleSheet } from 'styled-components';
|
||||
|
||||
class RootDocument extends Document {
|
||||
static async getInitialProps(ctx: any) {
|
||||
const sheet = new ServerStyleSheet();
|
||||
const originalRenderPage = ctx.renderPage;
|
||||
|
||||
try {
|
||||
ctx.renderPage = () =>
|
||||
originalRenderPage({
|
||||
enhanceApp: (App: any) => (props: any) =>
|
||||
sheet.collectStyles(<App {...props} />),
|
||||
});
|
||||
|
||||
const initialProps = await Document.getInitialProps(ctx);
|
||||
return {
|
||||
...initialProps,
|
||||
styles: (
|
||||
<>
|
||||
{initialProps.styles}
|
||||
{sheet.getStyleElement()}
|
||||
</>
|
||||
),
|
||||
};
|
||||
} finally {
|
||||
sheet.seal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default RootDocument;
|
||||
@@ -1,9 +1,13 @@
|
||||
import React from 'react';
|
||||
import Head from 'next/head';
|
||||
import Me from '../components/Me';
|
||||
import Social from '../components/Social';
|
||||
|
||||
const Frontpage: React.FC<{}> = () => (
|
||||
<>
|
||||
<Head>
|
||||
<title>Morten Olsen</title>
|
||||
</Head>
|
||||
<Me />
|
||||
<Social
|
||||
sites={[{
|
||||
|
||||
Reference in New Issue
Block a user