Created
May 16, 2018 23:18
-
-
Save stramel/67b76f1c13445709b112f0902a4042d3 to your computer and use it in GitHub Desktop.
Page overrides
This file contains 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
import App, { Container } from 'next/app' | |
import React from 'react' | |
class MyApp extends App { | |
render() { | |
const { | |
Component, pageProps | |
} = this.props | |
return ( | |
<Container> | |
<Component {...pageProps} /> | |
</Container> | |
) | |
} | |
} | |
export default MyApp |
This file contains 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
import React from 'react' | |
import Document, { Head, Main, NextScript } from 'next/document' | |
import 'styles/index.css' | |
import hoistNonReactStatics from 'hoist-non-react-statics' | |
import { ServerStyleSheet } from 'styled-components' | |
const hoistStatics = higherOrderComponent => BaseComponent => { | |
const NewComponent = higherOrderComponent(BaseComponent) | |
hoistNonReactStatics(NewComponent, BaseComponent) | |
return NewComponent | |
} | |
export default class MyDocument extends Document { | |
static getInitialProps({ renderPage }) { | |
const sheet = new ServerStyleSheet() | |
const enhancer = hoistStatics(App => props => sheet.collectStyles(<App {...props} />)) | |
const page = renderPage(enhancer) | |
const styleTags = sheet.getStyleElement() | |
return { ...page, styleTags } | |
} | |
render() { | |
return ( | |
<html lang='en-US'> | |
<Head> | |
<meta charSet='utf-8' /> | |
<meta | |
name='viewport' | |
content='width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes' | |
/> | |
<link rel='stylesheet' href='/_next/static/style.css' /> | |
{this.props.styleTags} | |
</Head> | |
<body> | |
<Main /> | |
<NextScript /> | |
</body> | |
</html> | |
) | |
} | |
} |
This file contains 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
export { default } from './home' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment