diff --git a/src/hooks/useSingleExecution/index.native.js b/src/hooks/useSingleExecution/index.native.js deleted file mode 100644 index 16a98152def..00000000000 --- a/src/hooks/useSingleExecution/index.native.js +++ /dev/null @@ -1,40 +0,0 @@ -import {useCallback, useRef, useState} from 'react'; -import {InteractionManager} from 'react-native'; - -type Action = (...params: T) => void | Promise; - -/** - * With any action passed in, it will only allow 1 such action to occur at a time. - */ -export default function useSingleExecution() { - const [isExecuting, setIsExecuting] = useState(false); - const isExecutingRef = useRef(); - - isExecutingRef.current = isExecuting; - - const singleExecution = useCallback( - (action: Action) => - (...params: T) => { - if (isExecutingRef.current) { - return; - } - - setIsExecuting(true); - isExecutingRef.current = true; - - const execution = action(...params); - InteractionManager.runAfterInteractions(() => { - if (!(execution instanceof Promise)) { - setIsExecuting(false); - return; - } - execution.finally(() => { - setIsExecuting(false); - }); - }); - }, - [], - ); - - return {isExecuting, singleExecution}; -} diff --git a/src/hooks/useSingleExecution.ts b/src/hooks/useSingleExecution/index.native.ts similarity index 100% rename from src/hooks/useSingleExecution.ts rename to src/hooks/useSingleExecution/index.native.ts diff --git a/src/hooks/useSingleExecution/index.js b/src/hooks/useSingleExecution/index.ts similarity index 75% rename from src/hooks/useSingleExecution/index.js rename to src/hooks/useSingleExecution/index.ts index 0b2e565c46b..c37087d27c5 100644 --- a/src/hooks/useSingleExecution/index.js +++ b/src/hooks/useSingleExecution/index.ts @@ -1,16 +1,16 @@ import {useCallback} from 'react'; +type Action = (...params: T) => void | Promise; + /** * This hook was specifically written for native issue * more information: https://github.com/Expensify/App/pull/24614 https://github.com/Expensify/App/pull/24173 * on web we don't need this mechanism so we just call the action directly. - * - * @returns {Object} */ export default function useSingleExecution() { const singleExecution = useCallback( - (action) => - (...params) => { + (action: Action) => + (...params: T) => { action(...params); }, [],