useUnmount
Executes a cleanup callback when the component unmounts, always using the latest function reference.
Loading preview...
The useUnmount hook runs a callback when the component unmounts from the DOM, reading the latest props and state via useLatest so your cleanup logic never suffers from stale closures.
Installation
Usage
Examples
Saving Unsaved Draft State on Unmount
Persist the latest form input value when the user navigates away and unmounts the component.
Reporting Analytics View Duration
Record how far the user progressed before closing a view.