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 :: passport jwt npm 
Javascript :: javascript module pattern 
Javascript :: post request with headers 
Javascript :: upi id regex 
Javascript :: useScroll 
Javascript :: how to push key value pair to object javascript 
Javascript :: react build blank page 
Javascript :: js date to timestamp 
Javascript :: Alpinejs notification 
Javascript :: How can I check if an object is an array 
Javascript :: array.slice 
Javascript :: three dots in js 
Javascript :: javascript rect 
Javascript :: redux react redux 
Javascript :: Minimal Project Angular 
Javascript :: active-class router-link 
Javascript :: js fetch json 
Javascript :: chart.js clear data 
Javascript :: js array reverse 
Javascript :: operator to return specific data of a mongodb query 
Javascript :: js socket.emit 
Javascript :: mongoose find multiple conditions 
Javascript :: react router remove location state on refresh 
Javascript :: abrir dialog angular materia 
Javascript :: datatable set row id 
Javascript :: add button dynamically in javascript 
Javascript :: Self Invoking Function Simpler Syntax 
Javascript :: react image source showing object module 
Javascript :: js scroll to bottom exact 
Javascript :: select 2 select trigger 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =