6.46.8 • Published 4 days ago

@gasket/nextjs v6.46.8

Weekly downloads
18
License
MIT
Repository
github
Last release
4 days ago

@gasket/nextjs

Gasket integrations for Next.js apps.

Installation

npm i @gasket/nextjs

Components

withGasketData

Use this to extend your Next.js Document to automatically inject a script containing the gasketData for use with the @gasket/data package.

Signature

  • withGasketData(options)(Document)

Props

  • [options] - (object) Optional configuration
    • index - (number) Force the script to be inject at a certain child index of the body

Example

This is the simplest and most common setup:

// pages/_document.js
import Document from 'next/document';
import { withGasketData } from '@gasket/next';

export default withGasketData()(Document);

By default this will inject the script in the <body/> after the Next.js <Main/> component, but before <NextScript/>. This also works for a custom Document.

Example forced index

However, there may be situations where you want to inject the gasketData script at a particular child index of the <body/>. To do so, you can set the index in the decorator options.

// pages/_document.js
import Document, { Html, Head, Main, NextScript } from 'next/document'
import { withGasketData } from '@gasket/next';

class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const initialProps = await Document.getInitialProps(ctx)
    return { ...initialProps }
  }

  render() {
    return (
      <Html>
        <Head />
        <body>
          <Main />
          <footer>Some custom content</footer>
          <NextScript />
        </body>
      </Html>
    )
  }
}

export default withGasketData({ index: 2 })(MyDocument);

In this example, the gasketData script will be injected after the custom <footer/> instead of right after <Main/>.

This is especially useful if you are somehow nesting or extending the <Main/> and <NextScript/> components and the decorator cannot find the right place to inject the script.

License

MIT

7.0.0-next.9

4 days ago

7.0.0-next.10

4 days ago

7.0.0-next.7

4 days ago

7.0.0-next.11

4 days ago

7.0.0-next.8

4 days ago

7.0.0-next.12

4 days ago

7.0.0-next.13

4 days ago

7.0.0-next.6

4 days ago

7.0.0-next.20

4 days ago

7.0.0-next.5

5 days ago

6.46.8

6 days ago

7.0.0-next.4

7 days ago

7.0.0-next.3

11 days ago

7.0.0-next.2

18 days ago

7.0.0-next.1

19 days ago

7.0.0-next.0

19 days ago

6.46.7

28 days ago

7.0.0-cli.7

1 month ago

7.0.0-cli.6

1 month ago

6.46.1-cli.0

2 months ago

7.0.0-cli.5

2 months ago

7.0.0-cli.4

2 months ago

7.0.0-cli.1

2 months ago

7.0.0-cli.0

2 months ago

7.0.0-cli.3

2 months ago

7.0.0-cli.2

2 months ago

7.0.0-canary.1

2 months ago

6.45.2

3 months ago

6.45.0

4 months ago

6.43.0

7 months ago

6.42.0

7 months ago

6.41.1

8 months ago

6.42.0-canary.1

8 months ago

6.42.0-canary.2

8 months ago

6.42.0-canary.0

8 months ago

6.40.0

11 months ago

6.39.0

11 months ago

6.38.1

1 year ago

6.36.1

1 year ago

6.37.0

1 year ago

6.34.6

2 years ago

6.35.0

1 year ago

6.34.3

2 years ago

6.34.4

2 years ago

6.34.2

2 years ago

6.21.0

2 years ago

6.24.0

2 years ago

6.20.3

2 years ago

6.20.2

2 years ago

6.11.1

2 years ago

6.10.1

2 years ago

6.10.0

2 years ago

6.14.0

2 years ago

6.9.0

2 years ago

6.17.0

2 years ago

6.17.1

2 years ago

6.8.0

3 years ago

6.4.0

3 years ago

6.0.12

3 years ago

6.0.9

3 years ago

6.0.0

3 years ago

6.0.0-canary.13

3 years ago

6.0.0-canary.9

3 years ago

6.0.0-canary.8

3 years ago

6.0.0-canary.4

3 years ago

6.0.0-canary.2

4 years ago