Home > Software design >  how can dynamically add script in document.js
how can dynamically add script in document.js

Time:07-15

how can dynamically add script in document.js

in document.js there is no accsess to props

so how can conditionaly add script ?

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

export default function Document() {
  return (
    <Html>
      <Head />
      <body>
        <Main />
        <NextScript />
      </body>
    </Html>
  )
}

CodePudding user response:

Since this seems to be a react component, your js code would be placed inside your functional component and before your JSX return.

  export default function Document() {

    // js code goes in here

    return (
      <Html>
        <Head />
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    );
  }
  • Related