@hyper-fetch/react 5.5.0 → 5.7.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.
@@ -125,26 +125,6 @@ export const useTrackedState = <T extends RequestInstance>({
125
125
  return false;
126
126
  };
127
127
 
128
- const mapResponseData = (
129
- data: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>>,
130
- ):
131
- | Promise<CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>>>
132
- | CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>> => {
133
- if (responseMapper) {
134
- const response = responseMapper(data);
135
- if (response instanceof Promise) {
136
- return new Promise((resolve) => {
137
- (async () => {
138
- const newResponse = await response;
139
- resolve({ ...data, ...newResponse });
140
- })();
141
- });
142
- }
143
- return { ...data, ...response };
144
- }
145
- return data;
146
- };
147
-
148
128
  const handleCacheData = (
149
129
  cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>>,
150
130
  ) => {
@@ -178,15 +158,15 @@ export const useTrackedState = <T extends RequestInstance>({
178
158
  const setCacheData = (
179
159
  cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>>,
180
160
  ): Promise<void> | void => {
181
- const data = mapResponseData(cacheData);
161
+ const data = responseMapper ? responseMapper(cacheData) : cacheData;
182
162
 
183
163
  if (data instanceof Promise) {
184
164
  return (async () => {
185
165
  const promiseData = await data;
186
- handleCacheData(promiseData);
166
+ handleCacheData({ ...cacheData, ...promiseData });
187
167
  })();
188
168
  }
189
- return handleCacheData(data);
169
+ return handleCacheData({ ...cacheData, ...data });
190
170
  };
191
171
 
192
172
  // ******************
@@ -10,7 +10,7 @@ export const useFetchDefaultOptions: DefaultOptionsType = {
10
10
  dependencies: [],
11
11
  disabled: false,
12
12
  dependencyTracking: true,
13
- fetchOnMount: true,
13
+ revalidate: true,
14
14
  initialData: null,
15
15
  refresh: false,
16
16
  refreshTime: DateInterval.hour,
@@ -25,7 +25,7 @@ export const useFetch = <RequestType extends RequestInstance>(
25
25
  dependencies = useFetchDefaultOptions.dependencies,
26
26
  disabled = useFetchDefaultOptions.disabled,
27
27
  dependencyTracking = useFetchDefaultOptions.dependencyTracking,
28
- fetchOnMount = useFetchDefaultOptions.fetchOnMount,
28
+ revalidate = useFetchDefaultOptions.revalidate,
29
29
  initialData = useFetchDefaultOptions.initialData,
30
30
  refresh = useFetchDefaultOptions.refresh,
31
31
  refreshTime = useFetchDefaultOptions.refreshTime,
@@ -153,7 +153,7 @@ export const useFetch = <RequestType extends RequestInstance>(
153
153
  const initialFetchData = () => {
154
154
  const hasStaleData = getStaleStatus();
155
155
  const isFetching = getIsFetchingIdentity();
156
- if ((fetchOnMount || hasStaleData) && !isFetching) {
156
+ if ((revalidate || hasStaleData) && !isFetching) {
157
157
  handleFetch();
158
158
  }
159
159
  };
@@ -20,7 +20,7 @@ export type UseFetchOptionsType<T extends RequestInstance> = {
20
20
  /**
21
21
  * If `true` it will refetch data in background no matter if we have it from cache.
22
22
  */
23
- fetchOnMount?: boolean;
23
+ revalidate?: boolean;
24
24
  /**
25
25
  * If cache is empty we can use placeholder data.
26
26
  */