@react-pakistan/util-functions 1.23.89 → 1.23.90

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.
@@ -3,14 +3,19 @@ interface FetchResult {
3
3
  error: any;
4
4
  }
5
5
  interface FetchConfig extends RequestInit {
6
- callback?: (result: FetchResult) => void;
7
6
  autoFetch?: boolean;
7
+ callback?: (result: FetchResult) => void;
8
8
  }
9
9
  interface Return {
10
+ apiResult: API_RESULT | undefined;
10
11
  data: any;
11
12
  error: any;
12
- loading: boolean;
13
13
  fetchNow: (url?: string, config?: FetchConfig) => void;
14
+ loading: boolean;
15
+ }
16
+ export declare enum API_RESULT {
17
+ SUCCESS = "SUCCESS",
18
+ ERROR = "ERROR"
14
19
  }
15
20
  export declare const useFetch: (url: string, config?: FetchConfig) => Return;
16
21
  export {};
@@ -59,14 +59,20 @@ var __rest = (this && this.__rest) || function (s, e) {
59
59
  return t;
60
60
  };
61
61
  Object.defineProperty(exports, "__esModule", { value: true });
62
- exports.useFetch = void 0;
62
+ exports.useFetch = exports.API_RESULT = void 0;
63
63
  var react_1 = require("react");
64
+ var API_RESULT;
65
+ (function (API_RESULT) {
66
+ API_RESULT["SUCCESS"] = "SUCCESS";
67
+ API_RESULT["ERROR"] = "ERROR";
68
+ })(API_RESULT || (exports.API_RESULT = API_RESULT = {}));
64
69
  var useFetch = function (url, config) {
65
70
  if (config === void 0) { config = {}; }
66
71
  var callback = config.callback, _a = config.autoFetch, autoFetch = _a === void 0 ? false : _a, defaultOptions = __rest(config, ["callback", "autoFetch"]);
67
72
  var _b = (0, react_1.useState)(null), data = _b[0], setData = _b[1];
68
73
  var _c = (0, react_1.useState)(null), error = _c[0], setError = _c[1];
69
74
  var _d = (0, react_1.useState)(false), loading = _d[0], setLoading = _d[1];
75
+ var _e = (0, react_1.useState)(undefined), apiResult = _e[0], setApiResult = _e[1];
70
76
  var abortControllerRef = (0, react_1.useRef)(null);
71
77
  var isMounted = (0, react_1.useRef)(true);
72
78
  (0, react_1.useEffect)(function () {
@@ -105,6 +111,7 @@ var useFetch = function (url, config) {
105
111
  if (isMounted.current) {
106
112
  setData(result);
107
113
  setError(null);
114
+ setApiResult(API_RESULT.SUCCESS);
108
115
  callback === null || callback === void 0 ? void 0 : callback({ data: result, error: null });
109
116
  }
110
117
  return [3 /*break*/, 6];
@@ -113,6 +120,7 @@ var useFetch = function (url, config) {
113
120
  if (isMounted.current) {
114
121
  setError(err_1);
115
122
  setData(null);
123
+ setApiResult(API_RESULT.ERROR);
116
124
  callback === null || callback === void 0 ? void 0 : callback({ data: null, error: err_1 });
117
125
  }
118
126
  return [3 /*break*/, 6];
@@ -131,10 +139,11 @@ var useFetch = function (url, config) {
131
139
  }
132
140
  }, [fetchNow, autoFetch]);
133
141
  return {
142
+ apiResult: apiResult,
134
143
  data: data,
135
144
  error: error,
136
- loading: loading,
137
145
  fetchNow: fetchNow,
146
+ loading: loading,
138
147
  };
139
148
  };
140
149
  exports.useFetch = useFetch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pakistan/util-functions",
3
- "version": "1.23.89",
3
+ "version": "1.23.90",
4
4
  "description": "A library of all util functions",
5
5
  "main": "index.js",
6
6
  "scripts": {