mirror of
https://github.com/outline/outline.git
synced 2026-11-21 05:24:03 +03:00
* Add JSDoc to hooks in app/hooks directory * lint --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom.moor@gmail.com>
21 lines
406 B
TypeScript
21 lines
406 B
TypeScript
import * as React from "react";
|
|
|
|
/**
|
|
* Hook that executes a callback when the component unmounts.
|
|
*
|
|
* @param callback Function to be called on component unmount
|
|
*/
|
|
const useUnmount = (callback: (...args: Array<any>) => any) => {
|
|
const ref = React.useRef(callback);
|
|
ref.current = callback;
|
|
|
|
React.useEffect(
|
|
() => () => {
|
|
ref.current();
|
|
},
|
|
[]
|
|
);
|
|
};
|
|
|
|
export default useUnmount;
|