next-plugin-hot-loader

0.1.1 • Public • Published

Next.js + React Hot Loader

This plugin enables React Hot Loader for Next.js.

⚠️ When to use it

Before you go further, here are some things you should know about react-hot-loader:

  • It was intentionally removed from Next.js due to the many issues it causes;
  • It might soon be deprecated in favour of Fast Refresh;
  • HMR is not the same as react-hot-loader; HMR works on Next.js out-of-the-box, but states are NOT kept between reloads.

This plugin can still be considered for those who desperately need state persisting during development, usually due to hard-to-achieve states.

This plugin also brings some implementation improvements over react-hot-loader, such as:

  • Opt-in on any component, to avoid affecting the whole application;
  • Removes itself transparently when NODE_ENV !== 'development'.

Installation

npm install --save next-plugin-hot-loader @hot-loader/react-dom

or

yarn add next-plugin-hot-loader @hot-loader/react-dom

Usage

Install plugin

Create a next.config.js in the root of your project (next to pages/ and package.json)

// next.config.js
const withHotLoader = require("next-plugin-hot-loader");
module.exports = withHotLoader({
  /* Next.js config options here */
});

withHotLoader should encapsulate a Next.js configuration object.

Opt-in on components

In any component (usually pages):

import { hot } from "next-plugin-hot-loader/hoc";

const Component = () => <div>Content</div>;

export default hot(Component);

Package Sidebar

Install

npm i next-plugin-hot-loader

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

3.92 kB

Total Files

3

Last publish

Collaborators

  • lucasconstantino