diff options
author | crupest <crupest@outlook.com> | 2023-09-21 21:05:04 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-09-21 21:05:04 +0800 |
commit | a8a8385cd959e4d9d57b8a35381d2851049c07ff (patch) | |
tree | a933e8a6c1e8b577149dba624514148507a61a50 /FrontEnd/src/components/hooks/useAutoUnsubscribePromise.ts | |
parent | 04863bd8ebb543a436bde0d49250010038ab9f90 (diff) | |
download | timeline-a8a8385cd959e4d9d57b8a35381d2851049c07ff.tar.gz timeline-a8a8385cd959e4d9d57b8a35381d2851049c07ff.tar.bz2 timeline-a8a8385cd959e4d9d57b8a35381d2851049c07ff.zip |
...
Diffstat (limited to 'FrontEnd/src/components/hooks/useAutoUnsubscribePromise.ts')
-rw-r--r-- | FrontEnd/src/components/hooks/useAutoUnsubscribePromise.ts | 24 |
1 files changed, 0 insertions, 24 deletions
diff --git a/FrontEnd/src/components/hooks/useAutoUnsubscribePromise.ts b/FrontEnd/src/components/hooks/useAutoUnsubscribePromise.ts deleted file mode 100644 index 01c5a1db..00000000 --- a/FrontEnd/src/components/hooks/useAutoUnsubscribePromise.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { useEffect, DependencyList } from "react"; - -export default function useAutoUnsubscribePromise<T>( - promiseGenerator: () => Promise<T> | null | undefined, - resultHandler: (data: T) => void, - dependencies?: DependencyList | undefined, -) { - useEffect(() => { - let subscribe = true; - const promise = promiseGenerator(); - if (promise) { - void promise.then((data) => { - if (subscribe) { - resultHandler(data); - } - }); - - return () => { - subscribe = false; - }; - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [promiseGenerator, resultHandler, ...(dependencies ?? [])]); -} |