ReferenceUtils
useDestroy
Hook that destroys an imperative instance after a real React unmount
Import
Usage
Pass an object with a destroy() method. Optional setup and teardown callbacks run around the instance’s mounted lifetime.
Destruction is deferred to a macrotask so React StrictMode’s simulated unmount and remount can cancel it. A real unmount runs teardown before destroy().