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
Parameter | Type | Description |
---|---|---|
_module | NodeModule | Reference to the current module where you invoke the fn |
cancelEffect | () => void | Fn that cleans up the ongoing effects |
Returns:
void
Example
const intervalId = setInterval(doStuff, 1000);
useHotCleanup(module, () => clearInterval(intervalId));