Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

next js custom document

import Document, { Html, Head, Main, NextScript } from 'next/document'

class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const originalRenderPage = ctx.renderPage

    // Run the React rendering logic synchronously
    ctx.renderPage = () =>
      originalRenderPage({
        // Useful for wrapping the whole react tree
        enhanceApp: (App) => App,
        // Useful for wrapping in a per-page basis
        enhanceComponent: (Component) => Component,
      })

    // Run the parent `getInitialProps`, it now includes the custom `renderPage`
    const initialProps = await Document.getInitialProps(ctx)

    return initialProps
  }

  render() {
    return (
      <Html>
        <Head />
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    )
  }
}

export default MyDocument
Comment

PREVIOUS NEXT
Code Example
Javascript :: encode in javascript 
Javascript :: es6 create array of multiples 
Javascript :: JavaScript how to put value 
Javascript :: google oauth logout 
Javascript :: ajax call do something while 
Javascript :: types of node in blockchain 
Javascript :: jquery is check 
Javascript :: react, scroll element into view 
Javascript :: how to copy to clipboard in react js 
Javascript :: set cursor type javascript 
Javascript :: append to top javascript 
Javascript :: mongoose update createdAt 
Javascript :: link in angular 
Javascript :: FullScreen Image By OnClick Jquery 
Javascript :: how to remove special characters from a string in javascript using regex 
Javascript :: react native scaling font 
Javascript :: angular get first element ngfor 
Javascript :: js check tab active 
Javascript :: redux saga delay 
Javascript :: javascript decode uri 
Javascript :: video preview javascript 
Javascript :: how create an index mongodb 
Javascript :: store id of an element jquery 
Javascript :: javascript date get future 5minutes 
Javascript :: remove div by class name javascript 
Javascript :: does onclick work for textboxes javascript 
Javascript :: json parse string 
Javascript :: postcss.config.js 
Javascript :: how to make nextjs image component responsive 
Javascript :: javascript sum array of objects by key 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =