use-hot-module-reload
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

use-hot-module-reload

React hook that triggers a callback after hot-module reloading has been performed (for any module, not just the one it was used in).

Works with modern versions of Webpack and Vite. Other bundlers may be added if they expose a way to listen for updates.

Installation

npm install --save use-hot-module-reload

Usage

import {useState, useCallback} from 'react'
import {useHotModuleReload} from 'use-hot-module-reload'

export function MyComponent() {
  const [lastHMRed, setLastHMRed] = useState('')
  const updateHMRTime = useCallback(() => setLastHMRed(new Date().toISOString()), [])
  useHotModuleReload(updateHMRTime)

  return <div>{lastHMRed && `Last hot module reload at: ${lastHMRed}`}</div>
}

License

MIT © Espen Hovlandsdal

Package Sidebar

Install

npm i use-hot-module-reload

Weekly Downloads

87,693

Version

2.0.0

License

MIT

Unpacked Size

16.1 kB

Total Files

11

Last publish

Collaborators

  • rexxars