diff options
Diffstat (limited to 'FrontEnd/src/components')
-rw-r--r-- | FrontEnd/src/components/hooks/index.ts | 2 | ||||
-rw-r--r-- | FrontEnd/src/components/hooks/useAutoUnsubscribePromise.ts | 24 | ||||
-rw-r--r-- | FrontEnd/src/components/hooks/useReloadKey.ts | 9 | ||||
-rw-r--r-- | FrontEnd/src/components/utilities/index.ts | 2 |
4 files changed, 12 insertions, 25 deletions
diff --git a/FrontEnd/src/components/hooks/index.ts b/FrontEnd/src/components/hooks/index.ts index 98ce729e..972bf5ce 100644 --- a/FrontEnd/src/components/hooks/index.ts +++ b/FrontEnd/src/components/hooks/index.ts @@ -2,4 +2,4 @@ export { useMobile } from "./responsive"; export { default as useClickOutside } from "./useClickOutside"; export { default as useScrollToBottom } from "./useScrollToBottom"; export { default as useWindowLeave } from "./useWindowLeave"; -export { default as useAutoUnsubscribePromise } from "./useAutoUnsubscribePromise"; +export { default as useReloadKey } from "./useReloadKey"; 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 ?? [])]); -} diff --git a/FrontEnd/src/components/hooks/useReloadKey.ts b/FrontEnd/src/components/hooks/useReloadKey.ts new file mode 100644 index 00000000..4f63f914 --- /dev/null +++ b/FrontEnd/src/components/hooks/useReloadKey.ts @@ -0,0 +1,9 @@ +import { useState } from "react"; + +export default function useReloadKey(): [ + key: number | string, + reload: () => void, +] { + const [key, setKey] = useState(0); + return [key, () => setKey((k) => k + 1)]; +} diff --git a/FrontEnd/src/components/utilities/index.ts b/FrontEnd/src/components/utilities/index.ts new file mode 100644 index 00000000..000c2640 --- /dev/null +++ b/FrontEnd/src/components/utilities/index.ts @@ -0,0 +1,2 @@ +export * from "~src/utilities"; + |