rn-custom-ui 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +477 -0
- package/lib/module/assets/images/close.png +0 -0
- package/lib/module/components/CustomCheckbox/index.js +99 -0
- package/lib/module/components/CustomCheckbox/index.js.map +1 -0
- package/lib/module/components/CustomCheckbox/styles.js +213 -0
- package/lib/module/components/CustomCheckbox/styles.js.map +1 -0
- package/lib/module/components/CustomCheckbox/types.js +4 -0
- package/lib/module/components/CustomCheckbox/types.js.map +1 -0
- package/lib/module/components/closeButton/index.js +45 -0
- package/lib/module/components/closeButton/index.js.map +1 -0
- package/lib/module/components/closeButton/types.js +4 -0
- package/lib/module/components/closeButton/types.js.map +1 -0
- package/lib/module/components/customButton/index.js +176 -0
- package/lib/module/components/customButton/index.js.map +1 -0
- package/lib/module/components/customButton/styles.js +282 -0
- package/lib/module/components/customButton/styles.js.map +1 -0
- package/lib/module/components/customButton/types.js +4 -0
- package/lib/module/components/customButton/types.js.map +1 -0
- package/lib/module/components/customDropDown/DropDownBottomSheet.js +57 -0
- package/lib/module/components/customDropDown/DropDownBottomSheet.js.map +1 -0
- package/lib/module/components/customDropDown/DropDownList.js +51 -0
- package/lib/module/components/customDropDown/DropDownList.js.map +1 -0
- package/lib/module/components/customDropDown/DropDownListItem.js +38 -0
- package/lib/module/components/customDropDown/DropDownListItem.js.map +1 -0
- package/lib/module/components/customDropDown/DropDownListModal.js +63 -0
- package/lib/module/components/customDropDown/DropDownListModal.js.map +1 -0
- package/lib/module/components/customDropDown/index.js +143 -0
- package/lib/module/components/customDropDown/index.js.map +1 -0
- package/lib/module/components/customDropDown/styles.js +189 -0
- package/lib/module/components/customDropDown/styles.js.map +1 -0
- package/lib/module/components/customDropDown/types.js +4 -0
- package/lib/module/components/customDropDown/types.js.map +1 -0
- package/lib/module/components/customDropDown/utils.js +17 -0
- package/lib/module/components/customDropDown/utils.js.map +1 -0
- package/lib/module/components/customList/ListEmpty.js +33 -0
- package/lib/module/components/customList/ListEmpty.js.map +1 -0
- package/lib/module/components/customList/ListFooterLoader.js +14 -0
- package/lib/module/components/customList/ListFooterLoader.js.map +1 -0
- package/lib/module/components/customList/defaultKeyExtractor.js +9 -0
- package/lib/module/components/customList/defaultKeyExtractor.js.map +1 -0
- package/lib/module/components/customList/getFlashList.js +19 -0
- package/lib/module/components/customList/getFlashList.js.map +1 -0
- package/lib/module/components/customList/index.js +117 -0
- package/lib/module/components/customList/index.js.map +1 -0
- package/lib/module/components/customList/styles.js +45 -0
- package/lib/module/components/customList/styles.js.map +1 -0
- package/lib/module/components/customList/types.js +4 -0
- package/lib/module/components/customList/types.js.map +1 -0
- package/lib/module/components/customModal/ModalFooter.js +44 -0
- package/lib/module/components/customModal/ModalFooter.js.map +1 -0
- package/lib/module/components/customModal/index.js +132 -0
- package/lib/module/components/customModal/index.js.map +1 -0
- package/lib/module/components/customModal/styles.js +123 -0
- package/lib/module/components/customModal/styles.js.map +1 -0
- package/lib/module/components/customModal/types.js +4 -0
- package/lib/module/components/customModal/types.js.map +1 -0
- package/lib/module/components/customModal/useCustomModal.js +23 -0
- package/lib/module/components/customModal/useCustomModal.js.map +1 -0
- package/lib/module/components/customNumberPad/NumberPadKey.js +39 -0
- package/lib/module/components/customNumberPad/NumberPadKey.js.map +1 -0
- package/lib/module/components/customNumberPad/index.js +156 -0
- package/lib/module/components/customNumberPad/index.js.map +1 -0
- package/lib/module/components/customNumberPad/styles.js +131 -0
- package/lib/module/components/customNumberPad/styles.js.map +1 -0
- package/lib/module/components/customNumberPad/types.js +4 -0
- package/lib/module/components/customNumberPad/types.js.map +1 -0
- package/lib/module/components/customNumberPad/useNumberPadInput.js +44 -0
- package/lib/module/components/customNumberPad/useNumberPadInput.js.map +1 -0
- package/lib/module/components/customNumberPad/utils.js +38 -0
- package/lib/module/components/customNumberPad/utils.js.map +1 -0
- package/lib/module/components/customSlideTabs/AnimatedTabIndicator.js +66 -0
- package/lib/module/components/customSlideTabs/AnimatedTabIndicator.js.map +1 -0
- package/lib/module/components/customSlideTabs/TabBarItem.js +61 -0
- package/lib/module/components/customSlideTabs/TabBarItem.js.map +1 -0
- package/lib/module/components/customSlideTabs/TabScene.js +88 -0
- package/lib/module/components/customSlideTabs/TabScene.js.map +1 -0
- package/lib/module/components/customSlideTabs/index.js +277 -0
- package/lib/module/components/customSlideTabs/index.js.map +1 -0
- package/lib/module/components/customSlideTabs/styles.js +132 -0
- package/lib/module/components/customSlideTabs/styles.js.map +1 -0
- package/lib/module/components/customSlideTabs/tabBarScroll.js +65 -0
- package/lib/module/components/customSlideTabs/tabBarScroll.js.map +1 -0
- package/lib/module/components/customSlideTabs/types.js +4 -0
- package/lib/module/components/customSlideTabs/types.js.map +1 -0
- package/lib/module/components/loading/index.js +34 -0
- package/lib/module/components/loading/index.js.map +1 -0
- package/lib/module/customFunctions/array.js +61 -0
- package/lib/module/customFunctions/array.js.map +1 -0
- package/lib/module/customFunctions/async.js +62 -0
- package/lib/module/customFunctions/async.js.map +1 -0
- package/lib/module/customFunctions/date.js +109 -0
- package/lib/module/customFunctions/date.js.map +1 -0
- package/lib/module/customFunctions/general.js +29 -0
- package/lib/module/customFunctions/general.js.map +1 -0
- package/lib/module/customFunctions/id.js +20 -0
- package/lib/module/customFunctions/id.js.map +1 -0
- package/lib/module/customFunctions/index.js +29 -0
- package/lib/module/customFunctions/index.js.map +1 -0
- package/lib/module/customFunctions/number.js +94 -0
- package/lib/module/customFunctions/number.js.map +1 -0
- package/lib/module/customFunctions/object.js +39 -0
- package/lib/module/customFunctions/object.js.map +1 -0
- package/lib/module/customFunctions/string.js +63 -0
- package/lib/module/customFunctions/string.js.map +1 -0
- package/lib/module/customFunctions/types.js +2 -0
- package/lib/module/customFunctions/types.js.map +1 -0
- package/lib/module/customFunctions/validation.js +34 -0
- package/lib/module/customFunctions/validation.js.map +1 -0
- package/lib/module/customHooks/errors.js +61 -0
- package/lib/module/customHooks/errors.js.map +1 -0
- package/lib/module/customHooks/fetchJson.js +36 -0
- package/lib/module/customHooks/fetchJson.js.map +1 -0
- package/lib/module/customHooks/index.js +10 -0
- package/lib/module/customHooks/index.js.map +1 -0
- package/lib/module/customHooks/internal.js +49 -0
- package/lib/module/customHooks/internal.js.map +1 -0
- package/lib/module/customHooks/types.js +2 -0
- package/lib/module/customHooks/types.js.map +1 -0
- package/lib/module/customHooks/useApi.js +91 -0
- package/lib/module/customHooks/useApi.js.map +1 -0
- package/lib/module/customHooks/useLazyApi.js +80 -0
- package/lib/module/customHooks/useLazyApi.js.map +1 -0
- package/lib/module/customHooks/useMutation.js +69 -0
- package/lib/module/customHooks/useMutation.js.map +1 -0
- package/lib/module/customHooks/usePaginatedApi.js +127 -0
- package/lib/module/customHooks/usePaginatedApi.js.map +1 -0
- package/lib/module/customHooks/usePollingApi.js +37 -0
- package/lib/module/customHooks/usePollingApi.js.map +1 -0
- package/lib/module/index.js +13 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/multiply.js +6 -0
- package/lib/module/multiply.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/components/CustomCheckbox/index.d.ts +5 -0
- package/lib/typescript/src/components/CustomCheckbox/index.d.ts.map +1 -0
- package/lib/typescript/src/components/CustomCheckbox/styles.d.ts +67 -0
- package/lib/typescript/src/components/CustomCheckbox/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/CustomCheckbox/types.d.ts +28 -0
- package/lib/typescript/src/components/CustomCheckbox/types.d.ts.map +1 -0
- package/lib/typescript/src/components/closeButton/index.d.ts +4 -0
- package/lib/typescript/src/components/closeButton/index.d.ts.map +1 -0
- package/lib/typescript/src/components/closeButton/types.d.ts +8 -0
- package/lib/typescript/src/components/closeButton/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customButton/index.d.ts +5 -0
- package/lib/typescript/src/components/customButton/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customButton/styles.d.ts +231 -0
- package/lib/typescript/src/components/customButton/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customButton/types.d.ts +46 -0
- package/lib/typescript/src/components/customButton/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/DropDownBottomSheet.d.ts +18 -0
- package/lib/typescript/src/components/customDropDown/DropDownBottomSheet.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/DropDownList.d.ts +17 -0
- package/lib/typescript/src/components/customDropDown/DropDownList.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/DropDownListItem.d.ts +15 -0
- package/lib/typescript/src/components/customDropDown/DropDownListItem.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/DropDownListModal.d.ts +19 -0
- package/lib/typescript/src/components/customDropDown/DropDownListModal.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/index.d.ts +5 -0
- package/lib/typescript/src/components/customDropDown/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/styles.d.ts +190 -0
- package/lib/typescript/src/components/customDropDown/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/types.d.ts +37 -0
- package/lib/typescript/src/components/customDropDown/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/utils.d.ts +4 -0
- package/lib/typescript/src/components/customDropDown/utils.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/ListEmpty.d.ts +10 -0
- package/lib/typescript/src/components/customList/ListEmpty.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/ListFooterLoader.d.ts +3 -0
- package/lib/typescript/src/components/customList/ListFooterLoader.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/defaultKeyExtractor.d.ts +2 -0
- package/lib/typescript/src/components/customList/defaultKeyExtractor.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/getFlashList.d.ts +6 -0
- package/lib/typescript/src/components/customList/getFlashList.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/index.d.ts +11 -0
- package/lib/typescript/src/components/customList/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/styles.d.ts +42 -0
- package/lib/typescript/src/components/customList/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/types.d.ts +33 -0
- package/lib/typescript/src/components/customList/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customModal/ModalFooter.d.ts +12 -0
- package/lib/typescript/src/components/customModal/ModalFooter.d.ts.map +1 -0
- package/lib/typescript/src/components/customModal/index.d.ts +6 -0
- package/lib/typescript/src/components/customModal/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customModal/styles.d.ts +83 -0
- package/lib/typescript/src/components/customModal/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customModal/types.d.ts +36 -0
- package/lib/typescript/src/components/customModal/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customModal/useCustomModal.d.ts +8 -0
- package/lib/typescript/src/components/customModal/useCustomModal.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/NumberPadKey.d.ts +23 -0
- package/lib/typescript/src/components/customNumberPad/NumberPadKey.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/index.d.ts +7 -0
- package/lib/typescript/src/components/customNumberPad/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/styles.d.ts +37 -0
- package/lib/typescript/src/components/customNumberPad/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/types.d.ts +47 -0
- package/lib/typescript/src/components/customNumberPad/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/useNumberPadInput.d.ts +16 -0
- package/lib/typescript/src/components/customNumberPad/useNumberPadInput.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/utils.d.ts +4 -0
- package/lib/typescript/src/components/customNumberPad/utils.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/AnimatedTabIndicator.d.ts +16 -0
- package/lib/typescript/src/components/customSlideTabs/AnimatedTabIndicator.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/TabBarItem.d.ts +23 -0
- package/lib/typescript/src/components/customSlideTabs/TabBarItem.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/TabScene.d.ts +21 -0
- package/lib/typescript/src/components/customSlideTabs/TabScene.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/index.d.ts +5 -0
- package/lib/typescript/src/components/customSlideTabs/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/styles.d.ts +130 -0
- package/lib/typescript/src/components/customSlideTabs/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/tabBarScroll.d.ts +15 -0
- package/lib/typescript/src/components/customSlideTabs/tabBarScroll.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/types.d.ts +68 -0
- package/lib/typescript/src/components/customSlideTabs/types.d.ts.map +1 -0
- package/lib/typescript/src/components/loading/index.d.ts +7 -0
- package/lib/typescript/src/components/loading/index.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/array.d.ts +7 -0
- package/lib/typescript/src/customFunctions/array.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/async.d.ts +9 -0
- package/lib/typescript/src/customFunctions/async.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/date.d.ts +18 -0
- package/lib/typescript/src/customFunctions/date.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/general.d.ts +7 -0
- package/lib/typescript/src/customFunctions/general.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/id.d.ts +4 -0
- package/lib/typescript/src/customFunctions/id.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/index.d.ts +26 -0
- package/lib/typescript/src/customFunctions/index.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/number.d.ts +15 -0
- package/lib/typescript/src/customFunctions/number.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/object.d.ts +6 -0
- package/lib/typescript/src/customFunctions/object.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/string.d.ts +20 -0
- package/lib/typescript/src/customFunctions/string.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/types.d.ts +22 -0
- package/lib/typescript/src/customFunctions/types.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/validation.d.ts +11 -0
- package/lib/typescript/src/customFunctions/validation.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/errors.d.ts +16 -0
- package/lib/typescript/src/customHooks/errors.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/fetchJson.d.ts +5 -0
- package/lib/typescript/src/customHooks/fetchJson.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/index.d.ts +9 -0
- package/lib/typescript/src/customHooks/index.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/internal.d.ts +12 -0
- package/lib/typescript/src/customHooks/internal.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/types.d.ts +49 -0
- package/lib/typescript/src/customHooks/types.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/useApi.d.ts +13 -0
- package/lib/typescript/src/customHooks/useApi.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/useLazyApi.d.ts +14 -0
- package/lib/typescript/src/customHooks/useLazyApi.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/useMutation.d.ts +15 -0
- package/lib/typescript/src/customHooks/useMutation.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/usePaginatedApi.d.ts +19 -0
- package/lib/typescript/src/customHooks/usePaginatedApi.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/usePollingApi.d.ts +13 -0
- package/lib/typescript/src/customHooks/usePollingApi.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +11 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/multiply.d.ts +2 -0
- package/lib/typescript/src/multiply.d.ts.map +1 -0
- package/package.json +181 -0
- package/src/assets/images/close.png +0 -0
- package/src/components/CustomCheckbox/index.tsx +143 -0
- package/src/components/CustomCheckbox/styles.ts +146 -0
- package/src/components/CustomCheckbox/types.ts +33 -0
- package/src/components/closeButton/index.tsx +40 -0
- package/src/components/closeButton/types.ts +13 -0
- package/src/components/customButton/index.tsx +288 -0
- package/src/components/customButton/styles.ts +247 -0
- package/src/components/customButton/types.ts +71 -0
- package/src/components/customDropDown/DropDownBottomSheet.tsx +70 -0
- package/src/components/customDropDown/DropDownList.tsx +88 -0
- package/src/components/customDropDown/DropDownListItem.tsx +74 -0
- package/src/components/customDropDown/DropDownListModal.tsx +86 -0
- package/src/components/customDropDown/index.tsx +213 -0
- package/src/components/customDropDown/styles.ts +184 -0
- package/src/components/customDropDown/types.ts +48 -0
- package/src/components/customDropDown/utils.ts +24 -0
- package/src/components/customList/ListEmpty.tsx +36 -0
- package/src/components/customList/ListFooterLoader.tsx +11 -0
- package/src/components/customList/defaultKeyExtractor.ts +7 -0
- package/src/components/customList/getFlashList.ts +26 -0
- package/src/components/customList/index.tsx +142 -0
- package/src/components/customList/styles.ts +43 -0
- package/src/components/customList/types.ts +60 -0
- package/src/components/customModal/ModalFooter.tsx +57 -0
- package/src/components/customModal/index.tsx +166 -0
- package/src/components/customModal/styles.ts +131 -0
- package/src/components/customModal/types.ts +48 -0
- package/src/components/customModal/useCustomModal.ts +25 -0
- package/src/components/customNumberPad/NumberPadKey.tsx +81 -0
- package/src/components/customNumberPad/index.tsx +204 -0
- package/src/components/customNumberPad/styles.ts +146 -0
- package/src/components/customNumberPad/types.ts +53 -0
- package/src/components/customNumberPad/useNumberPadInput.ts +56 -0
- package/src/components/customNumberPad/utils.ts +54 -0
- package/src/components/customSlideTabs/AnimatedTabIndicator.tsx +103 -0
- package/src/components/customSlideTabs/TabBarItem.tsx +118 -0
- package/src/components/customSlideTabs/TabScene.tsx +136 -0
- package/src/components/customSlideTabs/index.tsx +385 -0
- package/src/components/customSlideTabs/styles.ts +136 -0
- package/src/components/customSlideTabs/tabBarScroll.ts +92 -0
- package/src/components/customSlideTabs/types.ts +87 -0
- package/src/components/loading/index.tsx +34 -0
- package/src/customFunctions/array.ts +83 -0
- package/src/customFunctions/async.ts +85 -0
- package/src/customFunctions/date.ts +158 -0
- package/src/customFunctions/general.ts +35 -0
- package/src/customFunctions/id.ts +25 -0
- package/src/customFunctions/index.ts +91 -0
- package/src/customFunctions/number.ts +139 -0
- package/src/customFunctions/object.ts +59 -0
- package/src/customFunctions/string.ts +119 -0
- package/src/customFunctions/types.ts +25 -0
- package/src/customFunctions/validation.ts +49 -0
- package/src/customHooks/errors.ts +87 -0
- package/src/customHooks/fetchJson.ts +49 -0
- package/src/customHooks/index.ts +20 -0
- package/src/customHooks/internal.ts +67 -0
- package/src/customHooks/types.ts +71 -0
- package/src/customHooks/useApi.ts +107 -0
- package/src/customHooks/useLazyApi.ts +92 -0
- package/src/customHooks/useMutation.ts +97 -0
- package/src/customHooks/usePaginatedApi.ts +168 -0
- package/src/customHooks/usePollingApi.ts +48 -0
- package/src/index.tsx +63 -0
- package/src/multiply.tsx +3 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { useCallback, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getStatusFlags,
|
|
5
|
+
isAbortError,
|
|
6
|
+
normalizeApiError,
|
|
7
|
+
useAbortControllerRef,
|
|
8
|
+
useIsMounted,
|
|
9
|
+
} from './internal';
|
|
10
|
+
import type { ApiStatus, UseMutationOptions } from './types';
|
|
11
|
+
|
|
12
|
+
export const useMutation = <TData, TVariables = void, TError = unknown>(
|
|
13
|
+
mutationFn: (variables: TVariables, signal?: AbortSignal) => Promise<TData>,
|
|
14
|
+
options: UseMutationOptions<TData, TVariables, TError> = {}
|
|
15
|
+
) => {
|
|
16
|
+
const [data, setData] = useState<TData | null>(null);
|
|
17
|
+
const [error, setError] = useState<TError | null>(null);
|
|
18
|
+
const [status, setStatus] = useState<ApiStatus>('idle');
|
|
19
|
+
const [variables, setVariables] = useState<TVariables | null>(null);
|
|
20
|
+
|
|
21
|
+
const mutationRef = useRef(mutationFn);
|
|
22
|
+
const callbacksRef = useRef(options);
|
|
23
|
+
const isMountedRef = useIsMounted();
|
|
24
|
+
const { abort, create } = useAbortControllerRef();
|
|
25
|
+
|
|
26
|
+
mutationRef.current = mutationFn;
|
|
27
|
+
callbacksRef.current = options;
|
|
28
|
+
|
|
29
|
+
const mutateAsync = useCallback(
|
|
30
|
+
async (nextVariables: TVariables) => {
|
|
31
|
+
const controller = create();
|
|
32
|
+
|
|
33
|
+
setStatus('loading');
|
|
34
|
+
setError(null);
|
|
35
|
+
setVariables(nextVariables);
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const result = await mutationRef.current(
|
|
39
|
+
nextVariables,
|
|
40
|
+
controller.signal
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
if (controller.signal.aborted || !isMountedRef.current) {
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
setData(result);
|
|
48
|
+
setStatus('success');
|
|
49
|
+
callbacksRef.current.onSuccess?.(result, nextVariables);
|
|
50
|
+
callbacksRef.current.onSettled?.(result, null, nextVariables);
|
|
51
|
+
return result;
|
|
52
|
+
} catch (unknownError) {
|
|
53
|
+
if (isAbortError(unknownError)) {
|
|
54
|
+
return null as TData;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const parsedError = normalizeApiError<TError>(unknownError);
|
|
58
|
+
|
|
59
|
+
if (!isMountedRef.current) {
|
|
60
|
+
throw parsedError;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
setError(parsedError);
|
|
64
|
+
setStatus('error');
|
|
65
|
+
callbacksRef.current.onError?.(parsedError, nextVariables);
|
|
66
|
+
callbacksRef.current.onSettled?.(null, parsedError, nextVariables);
|
|
67
|
+
throw parsedError;
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
[create, isMountedRef]
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const mutate = useCallback(
|
|
74
|
+
(nextVariables: TVariables) => {
|
|
75
|
+
mutateAsync(nextVariables).catch(() => {});
|
|
76
|
+
},
|
|
77
|
+
[mutateAsync]
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const reset = useCallback(() => {
|
|
81
|
+
abort();
|
|
82
|
+
setData(null);
|
|
83
|
+
setError(null);
|
|
84
|
+
setVariables(null);
|
|
85
|
+
setStatus('idle');
|
|
86
|
+
}, [abort]);
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
data,
|
|
90
|
+
error,
|
|
91
|
+
variables,
|
|
92
|
+
...getStatusFlags(status),
|
|
93
|
+
mutate,
|
|
94
|
+
mutateAsync,
|
|
95
|
+
reset,
|
|
96
|
+
};
|
|
97
|
+
};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getStatusFlags,
|
|
5
|
+
isAbortError,
|
|
6
|
+
normalizeApiError,
|
|
7
|
+
useAbortControllerRef,
|
|
8
|
+
useDependencyKey,
|
|
9
|
+
useIsMounted,
|
|
10
|
+
} from './internal';
|
|
11
|
+
import type {
|
|
12
|
+
ApiStatus,
|
|
13
|
+
PaginatedFetcher,
|
|
14
|
+
PaginatedResponse,
|
|
15
|
+
UsePaginatedApiOptions,
|
|
16
|
+
} from './types';
|
|
17
|
+
|
|
18
|
+
export const usePaginatedApi = <TItem, TError = unknown>(
|
|
19
|
+
fetcher: PaginatedFetcher<TItem>,
|
|
20
|
+
options: UsePaginatedApiOptions<TItem, TError> = {}
|
|
21
|
+
) => {
|
|
22
|
+
const {
|
|
23
|
+
enabled = true,
|
|
24
|
+
initialPage = 1,
|
|
25
|
+
deps = [],
|
|
26
|
+
onSuccess,
|
|
27
|
+
onError,
|
|
28
|
+
} = options;
|
|
29
|
+
|
|
30
|
+
const [items, setItems] = useState<TItem[]>([]);
|
|
31
|
+
const [page, setPage] = useState(initialPage);
|
|
32
|
+
const [hasMore, setHasMore] = useState(true);
|
|
33
|
+
const [total, setTotal] = useState<number | undefined>(undefined);
|
|
34
|
+
const [error, setError] = useState<TError | null>(null);
|
|
35
|
+
const [status, setStatus] = useState<ApiStatus>(enabled ? 'loading' : 'idle');
|
|
36
|
+
const [isRefreshing, setIsRefreshing] = useState(false);
|
|
37
|
+
const [isLoadingMore, setIsLoadingMore] = useState(false);
|
|
38
|
+
|
|
39
|
+
const fetcherRef = useRef(fetcher);
|
|
40
|
+
const callbacksRef = useRef({ onSuccess, onError });
|
|
41
|
+
const isMountedRef = useIsMounted();
|
|
42
|
+
const { abort, create } = useAbortControllerRef();
|
|
43
|
+
const depsKey = useDependencyKey(deps);
|
|
44
|
+
|
|
45
|
+
fetcherRef.current = fetcher;
|
|
46
|
+
callbacksRef.current = { onSuccess, onError };
|
|
47
|
+
|
|
48
|
+
const applyResponse = useCallback(
|
|
49
|
+
(
|
|
50
|
+
response: PaginatedResponse<TItem>,
|
|
51
|
+
targetPage: number,
|
|
52
|
+
replace: boolean
|
|
53
|
+
) => {
|
|
54
|
+
setItems((current) =>
|
|
55
|
+
replace ? response.items : [...current, ...response.items]
|
|
56
|
+
);
|
|
57
|
+
setHasMore(response.hasMore);
|
|
58
|
+
setTotal(response.total);
|
|
59
|
+
setPage(targetPage);
|
|
60
|
+
setStatus('success');
|
|
61
|
+
callbacksRef.current.onSuccess?.(response, targetPage);
|
|
62
|
+
},
|
|
63
|
+
[]
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const fetchPage = useCallback(
|
|
67
|
+
async (targetPage: number, replace: boolean) => {
|
|
68
|
+
const controller = create();
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
const response = await fetcherRef.current(
|
|
72
|
+
targetPage,
|
|
73
|
+
controller.signal
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
if (controller.signal.aborted || !isMountedRef.current) {
|
|
77
|
+
return response;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
applyResponse(response, targetPage, replace);
|
|
81
|
+
setError(null);
|
|
82
|
+
return response;
|
|
83
|
+
} catch (unknownError) {
|
|
84
|
+
if (isAbortError(unknownError)) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const parsedError = normalizeApiError<TError>(unknownError);
|
|
89
|
+
|
|
90
|
+
if (!isMountedRef.current) {
|
|
91
|
+
throw parsedError;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
setError(parsedError);
|
|
95
|
+
setStatus('error');
|
|
96
|
+
callbacksRef.current.onError?.(parsedError, targetPage);
|
|
97
|
+
throw parsedError;
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
[applyResponse, create, isMountedRef]
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const refresh = useCallback(async () => {
|
|
104
|
+
setIsRefreshing(true);
|
|
105
|
+
setStatus('loading');
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
await fetchPage(initialPage, true);
|
|
109
|
+
} finally {
|
|
110
|
+
if (isMountedRef.current) {
|
|
111
|
+
setIsRefreshing(false);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}, [fetchPage, initialPage, isMountedRef]);
|
|
115
|
+
|
|
116
|
+
const loadMore = useCallback(async () => {
|
|
117
|
+
if (!hasMore || isLoadingMore || status === 'loading') {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
setIsLoadingMore(true);
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
return await fetchPage(page + 1, false);
|
|
125
|
+
} finally {
|
|
126
|
+
if (isMountedRef.current) {
|
|
127
|
+
setIsLoadingMore(false);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}, [fetchPage, hasMore, isLoadingMore, isMountedRef, page, status]);
|
|
131
|
+
|
|
132
|
+
const reset = useCallback(() => {
|
|
133
|
+
abort();
|
|
134
|
+
setItems([]);
|
|
135
|
+
setPage(initialPage);
|
|
136
|
+
setHasMore(true);
|
|
137
|
+
setTotal(undefined);
|
|
138
|
+
setError(null);
|
|
139
|
+
setStatus('idle');
|
|
140
|
+
setIsRefreshing(false);
|
|
141
|
+
setIsLoadingMore(false);
|
|
142
|
+
}, [abort, initialPage]);
|
|
143
|
+
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
if (!enabled) {
|
|
146
|
+
abort();
|
|
147
|
+
setStatus('idle');
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
setStatus('loading');
|
|
152
|
+
fetchPage(initialPage, true).catch(() => undefined);
|
|
153
|
+
}, [abort, depsKey, enabled, fetchPage, initialPage]);
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
items,
|
|
157
|
+
page,
|
|
158
|
+
hasMore,
|
|
159
|
+
total,
|
|
160
|
+
error,
|
|
161
|
+
isRefreshing,
|
|
162
|
+
isLoadingMore,
|
|
163
|
+
...getStatusFlags(status),
|
|
164
|
+
refresh,
|
|
165
|
+
loadMore,
|
|
166
|
+
reset,
|
|
167
|
+
};
|
|
168
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { AppState } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { useApi } from './useApi';
|
|
5
|
+
import type { ApiFetcher, UsePollingApiOptions } from './types';
|
|
6
|
+
|
|
7
|
+
export const usePollingApi = <TData, TError = unknown>(
|
|
8
|
+
fetcher: ApiFetcher<TData>,
|
|
9
|
+
options: UsePollingApiOptions<TData, TError>
|
|
10
|
+
) => {
|
|
11
|
+
const {
|
|
12
|
+
intervalMs,
|
|
13
|
+
pollWhenHidden = false,
|
|
14
|
+
pauseOnError = true,
|
|
15
|
+
enabled = true,
|
|
16
|
+
...apiOptions
|
|
17
|
+
} = options;
|
|
18
|
+
|
|
19
|
+
const api = useApi<TData, TError>(fetcher, {
|
|
20
|
+
...apiOptions,
|
|
21
|
+
enabled,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const apiRef = useRef(api);
|
|
25
|
+
apiRef.current = api;
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!enabled || intervalMs <= 0) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (pauseOnError && api.isError) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const intervalId = setInterval(() => {
|
|
37
|
+
if (!pollWhenHidden && AppState.currentState !== 'active') {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
apiRef.current.refetch().catch(() => {});
|
|
42
|
+
}, intervalMs);
|
|
43
|
+
|
|
44
|
+
return () => clearInterval(intervalId);
|
|
45
|
+
}, [api.isError, enabled, intervalMs, pauseOnError, pollWhenHidden]);
|
|
46
|
+
|
|
47
|
+
return api;
|
|
48
|
+
};
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export { multiply } from './multiply';
|
|
2
|
+
export * from './customFunctions';
|
|
3
|
+
export * from './customHooks';
|
|
4
|
+
export {
|
|
5
|
+
default as CustomButton,
|
|
6
|
+
type ButtonContentAlign,
|
|
7
|
+
type ButtonSize,
|
|
8
|
+
type ButtonVariant,
|
|
9
|
+
type CustomButtonProps,
|
|
10
|
+
type IconOnlyShape,
|
|
11
|
+
} from './components/customButton';
|
|
12
|
+
export {
|
|
13
|
+
default as CustomDropDown,
|
|
14
|
+
type CustomDropDownProps,
|
|
15
|
+
type DropDownItemImageAlign,
|
|
16
|
+
type DropDownListItem,
|
|
17
|
+
type DropDownMode,
|
|
18
|
+
type DropDownOption,
|
|
19
|
+
} from './components/customDropDown';
|
|
20
|
+
export {
|
|
21
|
+
default as CustomCheckbox,
|
|
22
|
+
type CheckboxLabelPosition,
|
|
23
|
+
type CheckboxShape,
|
|
24
|
+
type CheckboxSize,
|
|
25
|
+
type CheckboxVariant,
|
|
26
|
+
type CustomCheckboxProps,
|
|
27
|
+
} from './components/CustomCheckbox';
|
|
28
|
+
export {
|
|
29
|
+
default as CustomList,
|
|
30
|
+
defaultKeyExtractor,
|
|
31
|
+
getFlashList,
|
|
32
|
+
isFlashListAvailable,
|
|
33
|
+
type CustomListProps,
|
|
34
|
+
type ListEngine,
|
|
35
|
+
} from './components/customList';
|
|
36
|
+
export {
|
|
37
|
+
default as CustomNumberPad,
|
|
38
|
+
applyNumberPadKey,
|
|
39
|
+
useNumberPadInput,
|
|
40
|
+
NUMBER_PAD_ROWS,
|
|
41
|
+
type CustomNumberPadProps,
|
|
42
|
+
type NumberPadBottomLeftKey,
|
|
43
|
+
type NumberPadKeyConfig,
|
|
44
|
+
type NumberPadKeyType,
|
|
45
|
+
type NumberPadSize,
|
|
46
|
+
type NumberPadVariant,
|
|
47
|
+
type UseNumberPadInputOptions,
|
|
48
|
+
} from './components/customNumberPad';
|
|
49
|
+
export {
|
|
50
|
+
default as CustomModal,
|
|
51
|
+
useCustomModal,
|
|
52
|
+
type CustomModalProps,
|
|
53
|
+
type ModalAction,
|
|
54
|
+
type ModalPresentation,
|
|
55
|
+
} from './components/customModal';
|
|
56
|
+
export {
|
|
57
|
+
default as CustomSlideTabs,
|
|
58
|
+
type CustomSlideTabsProps,
|
|
59
|
+
type SlideTabItem,
|
|
60
|
+
type SlideTabSceneState,
|
|
61
|
+
type SlideTabFetcher,
|
|
62
|
+
type SlideTabIconComponent,
|
|
63
|
+
} from './components/customSlideTabs';
|
package/src/multiply.tsx
ADDED