1.2.0 • Published 4 months ago

@spark-web/next-utils v1.2.0

Weekly downloads
-
License
-
Repository
github
Last release
4 months ago

title: Next.js Utils

isExperimentalPackage: true

Universal Next Link

Resolves internal links using the Next.js Link component, which expects href to begin with a slash e.g. href="/page". Uses a traditional anchor element for everything else e.g. external, hash, tel, mailto.

For compatibility with TS + Spark the href property may only accept a string, so URL Objects must be resolved ahead of time. We recommend the url package for complex cases, though most of the time it's simple to do this manually.

You can pass the UniversalNextLink component to the linkComponent prop of the SparkProvider and all Link, TextLink, and ButtonLink components will automatically use the Next.js Link component for client-side transitions.

import { SparkProvider } from '@spark-web/core';
import { UniversalNextLink } from '@spark-web/next-utils';

export default function App({ Component, pageProps }) {
  return (
    <SparkProvider linkComponent={UniversalNextLink}>
      <Component {...pageProps} />
    </SparkProvider>
  );
}

Props

PropTypeDefaultDescription
hrefstringURL to direct to. Note that the URL needs to be an internal link (i.e. href='/page').

The UniversalNextLink props also includes HTML a anchor props and are not listed above.

propsWithCssText

Function that takes the initialProps from getInitialProps and inlines critical CSS server-side.

import { propsWithCssText } from '@spark-web/next-utils';
import NextDocument, { Head, Html, Main, NextScript } from 'next/document';

export default class Document extends NextDocument {
  static async getInitialProps(context) {
    const initialProps = await NextDocument.getInitialProps(context);
    return propsWithCssText(initialProps);
  }

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

Props

PropTypeDefaultDescription
initialPropsDocumentInitialPropsValue returned from the getInitialProps static method on the Document class (in next/document).
1.2.0

4 months ago

1.1.2

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago