0.1.2 • Published 7 years ago

next-page-decorator-invariant v0.1.2

Weekly downloads
10
License
MIT
Repository
github
Last release
7 years ago

Next.js page decorator invariant helper CircleCI

A decorator warns developers about incorrect usage of Next.js page decorators

Summary

When developing reusable decorators that target Next.js pages (which may or may not have a getInitialProps) it's useful to assert that the wrapped components is a page and not an ordinary component. For improved developer experience wrap any reusable page decorator with PageDecoratorInvariant and an error will be emitted when the decorator is improperly used.

Usage

  1. Install into your reusable component

    yarn add next-page-decorator-invariant
  2. Use the decorator

    Configure the decorator and use it inside your decorator

    // decorators/FooDecorator.js
    import PageDecoratorInvariant from 'next-page-decorator-invariant'
    const pageDecoratorInvariant = PageDecoratorInvariant('FooDecorator')
    
    default export Page => {
      const WrappedPage = pageDecoratorInvariant(Page)
      return props => <WrappedPage {...props} />
    }