@hyper-fetch/react 8.1.0 → 8.2.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/README.md +191 -51
- package/__tests__/features/helpers/use-tracked-state/use-tracked-state.utils.spec.ts +15 -0
- package/__tests__/features/use-fetch/use-fetch.base.spec.ts +3 -3
- package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts.map +1 -1
- package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts +1 -0
- package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts.map +1 -1
- package/dist/hooks/use-cache/use-cache.hooks.d.ts +1 -0
- package/dist/hooks/use-cache/use-cache.hooks.d.ts.map +1 -1
- package/dist/hooks/use-emitter/use-emitter.hooks.d.ts +1 -0
- package/dist/hooks/use-emitter/use-emitter.hooks.d.ts.map +1 -1
- package/dist/hooks/use-emitter/use-emitter.types.d.ts +1 -0
- package/dist/hooks/use-emitter/use-emitter.types.d.ts.map +1 -1
- package/dist/hooks/use-fetch/use-fetch.hooks.d.ts +2 -1
- package/dist/hooks/use-fetch/use-fetch.hooks.d.ts.map +1 -1
- package/dist/hooks/use-listener/use-listener.hooks.d.ts +1 -0
- package/dist/hooks/use-listener/use-listener.hooks.d.ts.map +1 -1
- package/dist/hooks/use-listener/use-listener.types.d.ts +1 -0
- package/dist/hooks/use-listener/use-listener.types.d.ts.map +1 -1
- package/dist/hooks/use-queue/use-queue.hooks.d.ts +2 -1
- package/dist/hooks/use-queue/use-queue.hooks.d.ts.map +1 -1
- package/dist/hooks/use-queue/use-queue.types.d.ts +6 -0
- package/dist/hooks/use-queue/use-queue.types.d.ts.map +1 -1
- package/dist/hooks/use-submit/use-submit.hooks.d.ts +2 -1
- package/dist/hooks/use-submit/use-submit.hooks.d.ts.map +1 -1
- package/dist/index.mjs +11 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/helpers/use-tracked-state/use-tracked-state.utils.ts +1 -3
- package/src/hooks/use-app-manager/use-app-manager.hooks.ts +1 -0
- package/src/hooks/use-cache/use-cache.hooks.ts +1 -0
- package/src/hooks/use-emitter/use-emitter.hooks.ts +1 -0
- package/src/hooks/use-emitter/use-emitter.types.ts +1 -0
- package/src/hooks/use-fetch/use-fetch.hooks.ts +2 -1
- package/src/hooks/use-listener/use-listener.hooks.ts +1 -0
- package/src/hooks/use-listener/use-listener.types.ts +1 -0
- package/src/hooks/use-queue/use-queue.hooks.ts +2 -1
- package/src/hooks/use-queue/use-queue.types.ts +6 -0
- package/src/hooks/use-submit/use-submit.hooks.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyper-fetch/react",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "React hooks and utils for the hyper-fetch",
|
|
5
5
|
"author": "Maciej Pyrc <maciekpyrc@gmail.com>, Kacper Skawina <kacper.skawina@gmail.com>",
|
|
6
6
|
"homepage": "https://hyperfetch.bettertyped.com/",
|
|
@@ -76,9 +76,7 @@ export const getValidCacheData = <T extends RequestInstance>(
|
|
|
76
76
|
initialResponse: NullableType<Partial<ExtractAdapterResolvedType<T>>>,
|
|
77
77
|
cacheData: NullableType<CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>>>,
|
|
78
78
|
): CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>> | null => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (!isStale && cacheData) {
|
|
79
|
+
if (cacheData) {
|
|
82
80
|
return cacheData;
|
|
83
81
|
}
|
|
84
82
|
|
|
@@ -4,6 +4,7 @@ import { useState } from "react";
|
|
|
4
4
|
|
|
5
5
|
import type { UseAppManagerReturnType } from "hooks/use-app-manager";
|
|
6
6
|
|
|
7
|
+
/** Track the application's online/offline and focus/blur state through the client's AppManager. */
|
|
7
8
|
export const useAppManager = <Client extends ClientInstance>(client: Client): UseAppManagerReturnType => {
|
|
8
9
|
const [online, setIsOnline] = useState(client.appManager.isOnline);
|
|
9
10
|
const [focused, setIsFocused] = useState(client.appManager.isFocused);
|
|
@@ -9,6 +9,7 @@ import { useRequestEvents, useTrackedState } from "helpers";
|
|
|
9
9
|
import { useProvider } from "provider";
|
|
10
10
|
import { createTrackedProxy } from "utils";
|
|
11
11
|
|
|
12
|
+
/** Subscribe to cache updates for a given request without triggering network activity. */
|
|
12
13
|
export const useCache = <T extends RequestInstance>(
|
|
13
14
|
request: T,
|
|
14
15
|
options?: UseCacheOptionsType<T>,
|
|
@@ -7,6 +7,7 @@ import { useSocketState } from "helpers";
|
|
|
7
7
|
import { useProvider } from "provider";
|
|
8
8
|
import { createTrackedProxy } from "utils";
|
|
9
9
|
|
|
10
|
+
/** Send messages through a socket emitter with tracked connection state and lifecycle callbacks. */
|
|
10
11
|
export const useEmitter = <EmitterType extends EmitterInstance>(
|
|
11
12
|
emitter: EmitterType,
|
|
12
13
|
options?: UseEmitterOptionsType,
|
|
@@ -20,7 +20,8 @@ const suspensePromiseMap = new Map<string, SuspenseEntry>();
|
|
|
20
20
|
const suspenseResultMap = new Map<string, { data: any; error: any; status: any; extra: any; success: boolean }>();
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* This
|
|
23
|
+
* This hook aims to retrieve data from the server. It automatically fetches on mount and
|
|
24
|
+
* refetches based on dependencies, with support for caching, polling, and suspense.
|
|
24
25
|
* @param request Request instance
|
|
25
26
|
* @param options Hook options
|
|
26
27
|
* @returns
|
|
@@ -7,6 +7,7 @@ import type { UseListenerOptionsType } from "hooks/use-listener";
|
|
|
7
7
|
import { useProvider } from "provider";
|
|
8
8
|
import { createTrackedProxy } from "utils";
|
|
9
9
|
|
|
10
|
+
/** Subscribe to incoming socket messages on a given listener topic with tracked connection state and callbacks. */
|
|
10
11
|
export const useListener = <ListenerType extends ListenerInstance>(
|
|
11
12
|
listener: ListenerType,
|
|
12
13
|
options?: UseListenerOptionsType,
|
|
@@ -16,7 +16,8 @@ const canUpdate = (
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* This hook allows to control
|
|
19
|
+
* This hook allows you to monitor and control dispatcher request queues for a given request,
|
|
20
|
+
* including starting, stopping, pausing, and inspecting pending/in-flight items.
|
|
20
21
|
* @param request
|
|
21
22
|
* @param options
|
|
22
23
|
* @returns
|
|
@@ -7,14 +7,20 @@ import type {
|
|
|
7
7
|
} from "@hyper-fetch/core";
|
|
8
8
|
|
|
9
9
|
export type UseQueueOptionsType = {
|
|
10
|
+
/** Which dispatcher to use: "auto" picks based on request method, "fetch" or "submit" forces a specific one */
|
|
10
11
|
dispatcherType?: "auto" | "fetch" | "submit";
|
|
12
|
+
/** When true, completed requests remain in the queue list for inspection */
|
|
11
13
|
keepFinishedRequests?: boolean;
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
export type QueueRequest<Request extends RequestInstance> = ResolvedQueueItemType<Request> & {
|
|
17
|
+
/** Whether the request has failed after all retry attempts */
|
|
15
18
|
failed?: boolean;
|
|
19
|
+
/** Whether the request was canceled before completing */
|
|
16
20
|
canceled?: boolean;
|
|
21
|
+
/** Whether the request was removed from the queue */
|
|
17
22
|
removed?: boolean;
|
|
23
|
+
/** Whether the request completed successfully */
|
|
18
24
|
success?: boolean;
|
|
19
25
|
/**
|
|
20
26
|
* Uploading progress for given request
|
|
@@ -21,7 +21,8 @@ import { useProvider } from "provider";
|
|
|
21
21
|
import { createTrackedProxy, getBounceData } from "utils";
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* This
|
|
24
|
+
* This hook aims to mutate data on the server. Unlike useFetch, it does not fire automatically -
|
|
25
|
+
* call the returned `submit` function to trigger the request (e.g., on button click).
|
|
25
26
|
* @param request
|
|
26
27
|
* @param options
|
|
27
28
|
* @returns
|