Created
November 9, 2018 18:14
-
-
Save dearfrankg/fecdb7d8af22414f28298694834badb6 to your computer and use it in GitHub Desktop.
evergreen-ui setup ssr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable react/no-danger, import/no-unresolved */ | |
import React from "react"; | |
import Document, { Head, Main, NextScript } from "next/document"; | |
import { extractStyles } from "evergreen-ui"; | |
export default class MyDocument extends Document { | |
static async getInitialProps({ renderPage }) { | |
const page = renderPage(); | |
// `css` is a string with css from both glamor and ui-box. | |
// No need to get the glamor css manually if you are using it elsewhere in your app. | |
// | |
// `hydrationScript` is a script you should render on the server. | |
// It contains a stringified version of the glamor and ui-box caches. | |
// Evergreen will look for that script on the client and automatically hydrate | |
// both glamor and ui-box. | |
const { css, hydrationScript } = extractStyles(); | |
return { | |
...page, | |
css, | |
hydrationScript | |
}; | |
} | |
render() { | |
return ( | |
<html> | |
<Head> | |
{/* <title>SSR in Next.js</title> */} | |
<style dangerouslySetInnerHTML={{ __html: this.props.css }} /> | |
{this.props.hydrationScript} | |
</Head> | |
<body> | |
<Main /> | |
<NextScript /> | |
</body> | |
</html> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment