App: add helper hooks

This commit is contained in:
rektdeckard
2021-05-30 23:17:33 -04:00
parent 0e50efb5ea
commit 73b66e2e86
5 changed files with 110 additions and 0 deletions

12
src/hooks/useUnmount.ts Normal file
View File

@@ -0,0 +1,12 @@
import { useRef, useEffect } from "react";
const useUnmount = (fn: () => any): void => {
const fnRef = useRef(fn);
// update the ref each render so if it change the newest callback will be invoked
fnRef.current = fn;
useEffect(() => () => fnRef.current(), []);
};
export default useUnmount;