import Document, { Head, Main, NextScript } from 'next/document'
export default class MyDocument extends Document {
static async getInitialProps (ctx) {
let options
const enhanceComponent = Component => (props) =>
RENDERED
const enhanceApp = Component => (props) => RENDERED
if (ctx.query.withEnhancer) {
options = enhanceComponent
} else if (ctx.query.withEnhanceComponent || ctx.query.withEnhanceApp) {
options = {}
if (ctx.query.withEnhanceComponent) {
options.enhanceComponent = enhanceComponent
}
if (ctx.query.withEnhanceApp) {
options.enhanceApp = enhanceApp
}
}
const result = ctx.renderPage(options)
return { ...result, customProperty: 'Hello Document' }
}
render () {
return (
{this.props.customProperty}
Hello Document HMR
)
}
}