Skip to main content

useHotCleanup()

Home > @backstage/backend-common > useHotCleanup

Warning: This API is now obsolete.

Hot module reloading is no longer supported for backends.

useHotCleanup allows cleanup of ongoing effects when a module is hot-reloaded during development. The cleanup function will be called whenever the module itself or any of its parent modules is hot-reloaded.

Useful for cleaning intervals, timers, requests etc

Signature:

function useHotCleanup(_module: NodeModule, cancelEffect: () => void): void;

Parameters

ParameterTypeDescription
_moduleNodeModuleReference to the current module where you invoke the fn
cancelEffect() => voidFn that cleans up the ongoing effects

Returns:

void

Example

const intervalId = setInterval(doStuff, 1000);
useHotCleanup(module, () => clearInterval(intervalId));