@faasjs/react 8.0.0-beta.29 → 8.0.0-beta.30
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 +0 -4
- package/dist/index.d.ts +61 -59
- package/dist/index.mjs +29 -30
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -37,14 +37,10 @@
|
|
|
37
37
|
|
|
38
38
|
- [BaseUrl](type-aliases/BaseUrl.md)
|
|
39
39
|
- [ErrorChildrenProps](type-aliases/ErrorChildrenProps.md)
|
|
40
|
-
- [FaasAction](type-aliases/FaasAction.md)
|
|
41
|
-
- [FaasActionUnionType](type-aliases/FaasActionUnionType.md)
|
|
42
40
|
- [FaasBrowserClientAction](type-aliases/FaasBrowserClientAction.md)
|
|
43
|
-
- [FaasData](type-aliases/FaasData.md)
|
|
44
41
|
- [FaasDataInjection](type-aliases/FaasDataInjection.md)
|
|
45
42
|
- [FaasDataWrapperProps](type-aliases/FaasDataWrapperProps.md)
|
|
46
43
|
- [FaasDataWrapperRef](type-aliases/FaasDataWrapperRef.md)
|
|
47
|
-
- [FaasParams](type-aliases/FaasParams.md)
|
|
48
44
|
- [FaasReactClientInstance](type-aliases/FaasReactClientInstance.md)
|
|
49
45
|
- [FaasReactClientOptions](type-aliases/FaasReactClientOptions.md)
|
|
50
46
|
- [MockHandler](type-aliases/MockHandler.md)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _$react from "react";
|
|
2
2
|
import { Component, ComponentProps, ComponentType, Dispatch, ErrorInfo, JSX, ReactElement, ReactNode, RefObject, SetStateAction } from "react";
|
|
3
3
|
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
|
-
import {
|
|
4
|
+
import { FaasActionPaths, FaasData, FaasParams } from "@faasjs/types";
|
|
5
5
|
|
|
6
6
|
//#region src/generate-id/index.d.ts
|
|
7
7
|
/**
|
|
@@ -108,7 +108,7 @@ type Options = RequestInit & {
|
|
|
108
108
|
options: Options;
|
|
109
109
|
headers: Record<string, string>;
|
|
110
110
|
}) => Promise<void>; /** Custom request implementation used instead of the native `fetch`. */
|
|
111
|
-
request?:
|
|
111
|
+
request?: (url: string, options: Options) => Promise<Response>; /** Base URL override for the current request. */
|
|
112
112
|
baseUrl?: BaseUrl; /** When `true`, return the native fetch response so callers can consume the stream manually. */
|
|
113
113
|
stream?: boolean;
|
|
114
114
|
};
|
|
@@ -121,7 +121,7 @@ type ResponseHeaders = {
|
|
|
121
121
|
/**
|
|
122
122
|
* Type definition for the FaasBrowserClient.action method.
|
|
123
123
|
*/
|
|
124
|
-
type FaasBrowserClientAction = <
|
|
124
|
+
type FaasBrowserClientAction = <Path extends FaasActionPaths>(action: Path, params?: FaasParams<Path>, options?: Options) => Promise<Response<FaasData<Path>> | Response>;
|
|
125
125
|
/**
|
|
126
126
|
* Properties for creating a Response object.
|
|
127
127
|
*/
|
|
@@ -176,7 +176,7 @@ declare class FaasBrowserClient {
|
|
|
176
176
|
/**
|
|
177
177
|
* Makes a request to a FaasJS function.
|
|
178
178
|
*/
|
|
179
|
-
action<
|
|
179
|
+
action<Path extends FaasActionPaths>(action: Path, params: FaasParams<Path>, options?: Options): Promise<Response<FaasData<Path>>>;
|
|
180
180
|
}
|
|
181
181
|
//#endregion
|
|
182
182
|
//#region src/faas/index.d.ts
|
|
@@ -186,14 +186,14 @@ declare class FaasBrowserClient {
|
|
|
186
186
|
* This helper forwards the request to `getClient`. When the registered
|
|
187
187
|
* client defines `onError`, the hook is invoked before the promise rejects.
|
|
188
188
|
*
|
|
189
|
-
* @template
|
|
189
|
+
* @template Path - Action path or response data type used for inference.
|
|
190
190
|
*
|
|
191
|
-
* @param {
|
|
192
|
-
* @param {FaasParams<
|
|
191
|
+
* @param {Path} action - Action path to invoke.
|
|
192
|
+
* @param {FaasParams<Path>} params - Parameters sent to the action.
|
|
193
193
|
* @param {Options} [options] - Optional per-request overrides such as headers or base URL.
|
|
194
194
|
* See the browser-client `Options` type for supported fields such as `headers`, `beforeRequest`,
|
|
195
195
|
* `request`, `baseUrl`, and `stream`.
|
|
196
|
-
* @returns {Promise<Response<FaasData<
|
|
196
|
+
* @returns {Promise<Response<FaasData<Path>>>} Response returned by the active browser client.
|
|
197
197
|
* @throws {ResponseError} When the request fails and the active client does not recover inside `onError`.
|
|
198
198
|
*
|
|
199
199
|
* @example
|
|
@@ -205,77 +205,77 @@ declare class FaasBrowserClient {
|
|
|
205
205
|
* console.log(response.data.title)
|
|
206
206
|
* ```
|
|
207
207
|
*/
|
|
208
|
-
declare function faas<
|
|
208
|
+
declare function faas<Path extends FaasActionPaths>(action: Path, params: FaasParams<Path>, options?: Options): Promise<Response<FaasData<Path>>>;
|
|
209
209
|
//#endregion
|
|
210
210
|
//#region src/FaasDataWrapper/index.d.ts
|
|
211
211
|
/**
|
|
212
212
|
* Request state injected by {@link useFaas}, {@link FaasDataWrapper}, and {@link withFaasData}.
|
|
213
213
|
*
|
|
214
|
-
* @template
|
|
214
|
+
* @template Path - Action path or response data type used for inference.
|
|
215
215
|
*/
|
|
216
|
-
type FaasDataInjection<
|
|
217
|
-
/** Action path associated with the current request state. */action:
|
|
218
|
-
params: FaasParams
|
|
216
|
+
type FaasDataInjection<Path extends FaasActionPaths> = {
|
|
217
|
+
/** Action path associated with the current request state. */action: Path; /** Params used for the most recent request attempt. */
|
|
218
|
+
params: FaasParams<Path>; /** Whether the request is currently in flight and should block the main UI. */
|
|
219
219
|
loading: boolean; /** Whether a background refresh request is currently in flight. */
|
|
220
220
|
refreshing: boolean; /** Number of times `reload()` or polling has triggered a new request. */
|
|
221
221
|
reloadTimes: number; /** Current resolved data value. */
|
|
222
|
-
data: FaasData
|
|
222
|
+
data: FaasData<Path>; /** Last request error, if one occurred. */
|
|
223
223
|
error: any; /** Promise representing the latest request. */
|
|
224
|
-
promise: Promise<Response<FaasData
|
|
224
|
+
promise: Promise<Response<FaasData<Path>>>;
|
|
225
225
|
/**
|
|
226
226
|
* Reloads data with new or existing parameters.
|
|
227
227
|
*
|
|
228
228
|
* When the source hook is currently skipped, calling `reload` clears the skip
|
|
229
229
|
* flag before starting the next request.
|
|
230
230
|
*/
|
|
231
|
-
reload(params?:
|
|
231
|
+
reload(params?: FaasParams<Path>, options?: {
|
|
232
232
|
silent?: boolean;
|
|
233
|
-
}): Promise<FaasData
|
|
234
|
-
setData: React.Dispatch<React.SetStateAction<FaasData
|
|
233
|
+
}): Promise<FaasData<Path>>; /** Controlled or internal setter for the resolved data value. */
|
|
234
|
+
setData: React.Dispatch<React.SetStateAction<FaasData<Path>>>; /** Setter for the loading flag. */
|
|
235
235
|
setLoading: React.Dispatch<React.SetStateAction<boolean>>; /** Setter for the latest request promise. */
|
|
236
|
-
setPromise: React.Dispatch<React.SetStateAction<Promise<Response<FaasData
|
|
236
|
+
setPromise: React.Dispatch<React.SetStateAction<Promise<Response<FaasData<Path>>>>>; /** Setter for the last request error. */
|
|
237
237
|
setError: React.Dispatch<React.SetStateAction<any>>;
|
|
238
238
|
};
|
|
239
239
|
/**
|
|
240
240
|
* Props for the {@link FaasDataWrapper} render-prop component.
|
|
241
241
|
*
|
|
242
|
-
* @template
|
|
242
|
+
* @template Path - Action path or response data type used for inference.
|
|
243
243
|
*/
|
|
244
|
-
type FaasDataWrapperProps<
|
|
245
|
-
/** Render prop invoked with the resolved request state after the first load completes. */render?(args: FaasDataInjection<
|
|
246
|
-
children?: React.ReactElement<Partial<FaasDataInjection<
|
|
244
|
+
type FaasDataWrapperProps<Path extends FaasActionPaths> = {
|
|
245
|
+
/** Render prop invoked with the resolved request state after the first load completes. */render?(args: FaasDataInjection<Path>): JSX.Element | JSX.Element[]; /** Child element cloned with injected request state after the first load completes. */
|
|
246
|
+
children?: React.ReactElement<Partial<FaasDataInjection<Path>>>; /** Element rendered before the first successful load. */
|
|
247
247
|
fallback?: JSX.Element | false; /** Action path to request. */
|
|
248
|
-
action:
|
|
249
|
-
params?: FaasParams
|
|
248
|
+
action: Path; /** Params sent to the action. */
|
|
249
|
+
params?: FaasParams<Path>; /** Milliseconds to wait after each completed request before refreshing data in the background. */
|
|
250
250
|
polling?: number | false; /** Callback invoked whenever the resolved data value changes. */
|
|
251
|
-
onDataChange?(args: FaasDataInjection<
|
|
252
|
-
data?: FaasData
|
|
253
|
-
setData?: React.Dispatch<React.SetStateAction<FaasData
|
|
251
|
+
onDataChange?(args: FaasDataInjection<Path>): void; /** Controlled data value used instead of internal state. */
|
|
252
|
+
data?: FaasData<Path>; /** Controlled setter used instead of internal state. */
|
|
253
|
+
setData?: React.Dispatch<React.SetStateAction<FaasData<Path>>>; /** Base URL override used for this wrapper instance. */
|
|
254
254
|
baseUrl?: BaseUrl; /** Imperative ref exposing the current injected request state. */
|
|
255
|
-
ref?: React.Ref<FaasDataWrapperRef<
|
|
255
|
+
ref?: React.Ref<FaasDataWrapperRef<Path>>;
|
|
256
256
|
};
|
|
257
257
|
/**
|
|
258
258
|
* Imperative ref shape exposed by {@link FaasDataWrapper}.
|
|
259
259
|
*
|
|
260
|
-
* @template
|
|
260
|
+
* @template Path - Action path or response data type used for inference.
|
|
261
261
|
*/
|
|
262
|
-
type FaasDataWrapperRef<
|
|
262
|
+
type FaasDataWrapperRef<Path extends FaasActionPaths> = FaasDataInjection<Path>;
|
|
263
263
|
/**
|
|
264
264
|
* Fetch FaasJS data and inject the result into a render prop or child element.
|
|
265
265
|
*
|
|
266
266
|
* The wrapper defers rendering `children` or `render` until the first request
|
|
267
267
|
* completes, then keeps passing the latest request state to the rendered output.
|
|
268
268
|
*
|
|
269
|
-
* @param {FaasDataWrapperProps<
|
|
270
|
-
* @param {(args: FaasDataInjection<
|
|
271
|
-
* @param {React.ReactElement<Partial<FaasDataInjection<
|
|
269
|
+
* @param {FaasDataWrapperProps<Path>} props - Wrapper props controlling the request and rendered fallback.
|
|
270
|
+
* @param {(args: FaasDataInjection<Path>) => JSX.Element | JSX.Element[]} [props.render] - Render prop that receives the resolved Faas request state.
|
|
271
|
+
* @param {React.ReactElement<Partial<FaasDataInjection<Path>>>} [props.children] - Child element cloned with injected Faas request state.
|
|
272
272
|
* @param {JSX.Element | false} [props.fallback] - Element rendered before the first successful load.
|
|
273
|
-
* @param {
|
|
274
|
-
* @param {FaasParams<
|
|
273
|
+
* @param {Path} props.action - Action path to request.
|
|
274
|
+
* @param {FaasParams<Path>} [props.params] - Params sent to the action.
|
|
275
275
|
* @param {number | false} [props.polling] - Milliseconds to wait after each completed request before refreshing data in the background.
|
|
276
|
-
* @param {(args: FaasDataInjection<
|
|
277
|
-
* @param {FaasData<
|
|
278
|
-
* @param {React.Dispatch<React.SetStateAction<FaasData<
|
|
276
|
+
* @param {(args: FaasDataInjection<Path>) => void} [props.onDataChange] - Callback invoked when the resolved data value changes.
|
|
277
|
+
* @param {FaasData<Path>} [props.data] - Controlled data value used instead of internal state.
|
|
278
|
+
* @param {React.Dispatch<React.SetStateAction<FaasData<Path>>>} [props.setData] - Controlled setter used instead of internal state.
|
|
279
279
|
* @param {BaseUrl} [props.baseUrl] - Base URL override used for this wrapper instance.
|
|
280
280
|
*
|
|
281
281
|
* @example
|
|
@@ -346,7 +346,7 @@ type FaasDataWrapperRef<PathOrData extends FaasActionUnionType$1 = any> = FaasDa
|
|
|
346
346
|
*
|
|
347
347
|
* When a ref is provided, it exposes the current Faas request state imperatively.
|
|
348
348
|
*/
|
|
349
|
-
declare const FaasDataWrapper: <
|
|
349
|
+
declare const FaasDataWrapper: <Path extends FaasActionPaths>(props: FaasDataWrapperProps<Path> & _$react.RefAttributes<FaasDataWrapperRef<Path>>) => React.ReactElement | null;
|
|
350
350
|
/**
|
|
351
351
|
* Wrap a component with {@link FaasDataWrapper} and inject Faas request state as props.
|
|
352
352
|
*
|
|
@@ -354,11 +354,11 @@ declare const FaasDataWrapper: <PathOrData extends FaasActionUnionType$1 = any>(
|
|
|
354
354
|
* preserve an existing component boundary. For new code, prefer `useFaas` or
|
|
355
355
|
* `FaasDataWrapper` when they express the request ownership more directly.
|
|
356
356
|
*
|
|
357
|
-
* @template
|
|
357
|
+
* @template Path - Action path or response data type used for inference.
|
|
358
358
|
* @template TComponentProps - Component props including injected Faas data fields.
|
|
359
359
|
* @param {React.FC<TComponentProps>} Component - Component that consumes injected Faas data props.
|
|
360
|
-
* @param {FaasDataWrapperProps<
|
|
361
|
-
* @returns {React.FC<Omit<TComponentProps, keyof FaasDataInjection<
|
|
360
|
+
* @param {FaasDataWrapperProps<Path>} faasProps - Request configuration forwarded to `FaasDataWrapper`.
|
|
361
|
+
* @returns {React.FC<Omit<TComponentProps, keyof FaasDataInjection<Path>> & Record<string, any>>} Component that accepts the original props minus the injected Faas data fields.
|
|
362
362
|
*
|
|
363
363
|
* @example
|
|
364
364
|
* ```tsx
|
|
@@ -380,7 +380,7 @@ declare const FaasDataWrapper: <PathOrData extends FaasActionUnionType$1 = any>(
|
|
|
380
380
|
* )
|
|
381
381
|
* ```
|
|
382
382
|
*/
|
|
383
|
-
declare function withFaasData<
|
|
383
|
+
declare function withFaasData<Path extends FaasActionPaths, TComponentProps extends Required<FaasDataInjection<Path>> = Required<FaasDataInjection<Path>>>(Component: React.FC<TComponentProps>, faasProps: FaasDataWrapperProps<Path>): React.FC<Omit<TComponentProps, keyof FaasDataInjection<Path>> & Record<string, any>>;
|
|
384
384
|
//#endregion
|
|
385
385
|
//#region src/useFaasRequest.d.ts
|
|
386
386
|
/**
|
|
@@ -398,7 +398,7 @@ type SharedUseFaasOptions<Params, Data> = {
|
|
|
398
398
|
params?: Params;
|
|
399
399
|
data?: Data;
|
|
400
400
|
setData?: React.Dispatch<React.SetStateAction<Data>>;
|
|
401
|
-
skip?: boolean | ((params: Params) => boolean);
|
|
401
|
+
skip?: boolean | ((params: Partial<Params>) => boolean);
|
|
402
402
|
debounce?: number;
|
|
403
403
|
polling?: number | false;
|
|
404
404
|
baseUrl?: BaseUrl;
|
|
@@ -408,9 +408,9 @@ type SharedUseFaasOptions<Params, Data> = {
|
|
|
408
408
|
/**
|
|
409
409
|
* Options that customize the {@link useFaas} request lifecycle.
|
|
410
410
|
*
|
|
411
|
-
* @template
|
|
411
|
+
* @template Path - Action path or response data type used for inference.
|
|
412
412
|
*/
|
|
413
|
-
type UseFaasOptions<
|
|
413
|
+
type UseFaasOptions<Path extends FaasActionPaths> = SharedUseFaasOptions<FaasParams<Path>, FaasData<Path>>;
|
|
414
414
|
/**
|
|
415
415
|
* Request FaasJS data and keep request state in React state.
|
|
416
416
|
*
|
|
@@ -418,13 +418,13 @@ type UseFaasOptions<PathOrData extends FaasActionUnionType$1> = SharedUseFaasOpt
|
|
|
418
418
|
* It sends an initial request unless `skip` is enabled, and returns request state
|
|
419
419
|
* plus helpers for reloading, background refreshing, updating data, and handling errors.
|
|
420
420
|
*
|
|
421
|
-
* @template
|
|
421
|
+
* @template Path - Action path or response data type used for inference.
|
|
422
422
|
*
|
|
423
|
-
* @param {
|
|
424
|
-
* @param {FaasParams<
|
|
425
|
-
* @param {UseFaasOptions<
|
|
423
|
+
* @param {Path} action - Action path to invoke.
|
|
424
|
+
* @param {FaasParams<Path>} defaultParams - Params used for the initial request and future reloads.
|
|
425
|
+
* @param {UseFaasOptions<Path>} [options] - Optional hook configuration such as controlled data, skip logic, debounce timing, polling, and base URL overrides.
|
|
426
426
|
* See the `UseFaasOptions` type for `params`, `data`, `setData`, `skip`, `debounce`, `polling`, and `baseUrl`.
|
|
427
|
-
* @returns {FaasDataInjection<
|
|
427
|
+
* @returns {FaasDataInjection<Path>} Request state and helper methods described by {@link FaasDataInjection}.
|
|
428
428
|
*
|
|
429
429
|
* @example
|
|
430
430
|
* ```tsx
|
|
@@ -457,7 +457,7 @@ type UseFaasOptions<PathOrData extends FaasActionUnionType$1> = SharedUseFaasOpt
|
|
|
457
457
|
* }
|
|
458
458
|
* ```
|
|
459
459
|
*/
|
|
460
|
-
declare function useFaas<
|
|
460
|
+
declare function useFaas<Path extends FaasActionPaths>(action: Path, defaultParams: FaasParams<Path>, options?: UseFaasOptions<Path>): FaasDataInjection<Path>;
|
|
461
461
|
//#endregion
|
|
462
462
|
//#region src/client.d.ts
|
|
463
463
|
/**
|
|
@@ -962,16 +962,18 @@ declare function useSplittingState<T extends Record<string, unknown>>(initialSta
|
|
|
962
962
|
type UseFaasStreamOptions = SharedUseFaasOptions<Record<string, any>, string>;
|
|
963
963
|
/**
|
|
964
964
|
* Result returned by {@link useFaasStream}.
|
|
965
|
+
*
|
|
966
|
+
* @template Path - Action path used for params inference.
|
|
965
967
|
*/
|
|
966
|
-
type UseFaasStreamResult = {
|
|
967
|
-
/** Action path currently associated with the stream request. */action:
|
|
968
|
-
params:
|
|
968
|
+
type UseFaasStreamResult<Path extends FaasActionPaths> = {
|
|
969
|
+
/** Action path currently associated with the stream request. */action: Path; /** Params used for the most recent request attempt. */
|
|
970
|
+
params: FaasParams<Path>; /** Whether the hook is currently waiting for stream data and should block the main UI. */
|
|
969
971
|
loading: boolean; /** Whether a background stream refresh is currently in flight. */
|
|
970
972
|
refreshing: boolean; /** Number of times `reload()` or polling has triggered a new request. */
|
|
971
973
|
reloadTimes: number; /** Accumulated text decoded from the stream response. */
|
|
972
974
|
data: string; /** Last error raised while opening or consuming the stream. */
|
|
973
975
|
error: any; /** Trigger a new streaming request with optional params. */
|
|
974
|
-
reload: (params?:
|
|
976
|
+
reload: (params?: FaasParams<Path>, options?: {
|
|
975
977
|
silent?: boolean;
|
|
976
978
|
}) => Promise<string>; /** Controlled or internal setter for the accumulated text. */
|
|
977
979
|
setData: React.Dispatch<React.SetStateAction<string>>; /** Setter for the loading flag. */
|
|
@@ -1015,7 +1017,7 @@ type UseFaasStreamResult = {
|
|
|
1015
1017
|
* }
|
|
1016
1018
|
* ```
|
|
1017
1019
|
*/
|
|
1018
|
-
declare function useFaasStream(action:
|
|
1020
|
+
declare function useFaasStream<Path extends FaasActionPaths>(action: Path, defaultParams: FaasParams<Path>, options?: UseFaasStreamOptions): UseFaasStreamResult<Path>;
|
|
1019
1021
|
//#endregion
|
|
1020
1022
|
//#region src/usePrevious/index.d.ts
|
|
1021
1023
|
/**
|
|
@@ -1065,4 +1067,4 @@ declare function usePrevious<T = any>(value: T): T | undefined;
|
|
|
1065
1067
|
*/
|
|
1066
1068
|
declare function useStateRef<T = any>(initialValue?: T): [T | null, Dispatch<SetStateAction<T | null>>, RefObject<T | null>];
|
|
1067
1069
|
//#endregion
|
|
1068
|
-
export { type BaseUrl, ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps,
|
|
1070
|
+
export { type BaseUrl, ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps, FaasBrowserClient, type FaasBrowserClientAction, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, FaasDataWrapperRef, FaasReactClient, FaasReactClientInstance, FaasReactClientOptions, type MockHandler, OnError, OptionalWrapper, OptionalWrapperProps, type Options, Response, ResponseError, type ResponseErrorProps, type ResponseHeaders, type ResponseProps, StateSetters, StatesWithSetters, UseFaasOptions, UseFaasStreamOptions, UseFaasStreamResult, createSplittingContext, equal, faas, generateId, getClient, setMock, useConstant, useEqualCallback, useEqualEffect, useEqualMemo, useEqualMemoize, useFaas, useFaasStream, usePrevious, useSplittingState, useStateRef, withFaasData };
|
package/dist/index.mjs
CHANGED
|
@@ -274,14 +274,14 @@ var FaasBrowserClient = class {
|
|
|
274
274
|
* This helper forwards the request to `getClient`. When the registered
|
|
275
275
|
* client defines `onError`, the hook is invoked before the promise rejects.
|
|
276
276
|
*
|
|
277
|
-
* @template
|
|
277
|
+
* @template Path - Action path or response data type used for inference.
|
|
278
278
|
*
|
|
279
|
-
* @param {
|
|
280
|
-
* @param {FaasParams<
|
|
279
|
+
* @param {Path} action - Action path to invoke.
|
|
280
|
+
* @param {FaasParams<Path>} params - Parameters sent to the action.
|
|
281
281
|
* @param {Options} [options] - Optional per-request overrides such as headers or base URL.
|
|
282
282
|
* See the browser-client `Options` type for supported fields such as `headers`, `beforeRequest`,
|
|
283
283
|
* `request`, `baseUrl`, and `stream`.
|
|
284
|
-
* @returns {Promise<Response<FaasData<
|
|
284
|
+
* @returns {Promise<Response<FaasData<Path>>>} Response returned by the active browser client.
|
|
285
285
|
* @throws {ResponseError} When the request fails and the active client does not recover inside `onError`.
|
|
286
286
|
*
|
|
287
287
|
* @example
|
|
@@ -465,16 +465,16 @@ function useEqualCallback(callback, dependencies) {
|
|
|
465
465
|
* The wrapper defers rendering `children` or `render` until the first request
|
|
466
466
|
* completes, then keeps passing the latest request state to the rendered output.
|
|
467
467
|
*
|
|
468
|
-
* @param {FaasDataWrapperProps<
|
|
469
|
-
* @param {(args: FaasDataInjection<
|
|
470
|
-
* @param {React.ReactElement<Partial<FaasDataInjection<
|
|
468
|
+
* @param {FaasDataWrapperProps<Path>} props - Wrapper props controlling the request and rendered fallback.
|
|
469
|
+
* @param {(args: FaasDataInjection<Path>) => JSX.Element | JSX.Element[]} [props.render] - Render prop that receives the resolved Faas request state.
|
|
470
|
+
* @param {React.ReactElement<Partial<FaasDataInjection<Path>>>} [props.children] - Child element cloned with injected Faas request state.
|
|
471
471
|
* @param {JSX.Element | false} [props.fallback] - Element rendered before the first successful load.
|
|
472
|
-
* @param {
|
|
473
|
-
* @param {FaasParams<
|
|
472
|
+
* @param {Path} props.action - Action path to request.
|
|
473
|
+
* @param {FaasParams<Path>} [props.params] - Params sent to the action.
|
|
474
474
|
* @param {number | false} [props.polling] - Milliseconds to wait after each completed request before refreshing data in the background.
|
|
475
|
-
* @param {(args: FaasDataInjection<
|
|
476
|
-
* @param {FaasData<
|
|
477
|
-
* @param {React.Dispatch<React.SetStateAction<FaasData<
|
|
475
|
+
* @param {(args: FaasDataInjection<Path>) => void} [props.onDataChange] - Callback invoked when the resolved data value changes.
|
|
476
|
+
* @param {FaasData<Path>} [props.data] - Controlled data value used instead of internal state.
|
|
477
|
+
* @param {React.Dispatch<React.SetStateAction<FaasData<Path>>>} [props.setData] - Controlled setter used instead of internal state.
|
|
478
478
|
* @param {BaseUrl} [props.baseUrl] - Base URL override used for this wrapper instance.
|
|
479
479
|
*
|
|
480
480
|
* @example
|
|
@@ -584,11 +584,11 @@ Object.assign(FaasDataWrapper, { displayName: "FaasDataWrapper" });
|
|
|
584
584
|
* preserve an existing component boundary. For new code, prefer `useFaas` or
|
|
585
585
|
* `FaasDataWrapper` when they express the request ownership more directly.
|
|
586
586
|
*
|
|
587
|
-
* @template
|
|
587
|
+
* @template Path - Action path or response data type used for inference.
|
|
588
588
|
* @template TComponentProps - Component props including injected Faas data fields.
|
|
589
589
|
* @param {React.FC<TComponentProps>} Component - Component that consumes injected Faas data props.
|
|
590
|
-
* @param {FaasDataWrapperProps<
|
|
591
|
-
* @returns {React.FC<Omit<TComponentProps, keyof FaasDataInjection<
|
|
590
|
+
* @param {FaasDataWrapperProps<Path>} faasProps - Request configuration forwarded to `FaasDataWrapper`.
|
|
591
|
+
* @returns {React.FC<Omit<TComponentProps, keyof FaasDataInjection<Path>> & Record<string, any>>} Component that accepts the original props minus the injected Faas data fields.
|
|
592
592
|
*
|
|
593
593
|
* @example
|
|
594
594
|
* ```tsx
|
|
@@ -625,16 +625,15 @@ function withFaasData(Component, faasProps) {
|
|
|
625
625
|
* retry-on-fetch-failure, polling, and queued reload promises while delegating the
|
|
626
626
|
* actual transport to `send`.
|
|
627
627
|
*
|
|
628
|
-
* @template
|
|
629
|
-
* @template
|
|
630
|
-
* @
|
|
631
|
-
* @param {UseFaasRequestArgs<Params, Result, RequestPromise>} args - Request lifecycle configuration.
|
|
628
|
+
* @template Path - Action path used for request params inference.
|
|
629
|
+
* @template TData - Data type returned by `send` and resolved by `reload()`.
|
|
630
|
+
* @param {UseFaasRequestArgs<Path>} args - Request lifecycle configuration.
|
|
632
631
|
* @param {string} args.action - Action path or request key used to trigger the lifecycle.
|
|
633
|
-
* @param {
|
|
634
|
-
* @param {Pick<SharedUseFaasOptions<
|
|
632
|
+
* @param {FaasParams<Path>} args.defaultParams - Initial params value stored by the lifecycle.
|
|
633
|
+
* @param {Pick<SharedUseFaasOptions<FaasParams<Path>, FaasData<Path>>, 'params' | 'skip' | 'debounce' | 'polling' | 'baseUrl'>} args.options - Shared request options used by the lifecycle.
|
|
635
634
|
* @param {(args: { silent: boolean }) => void} [args.beforeSend] - Optional callback invoked immediately before a request starts.
|
|
636
|
-
* @param {(result:
|
|
637
|
-
* @param {UseFaasRequestArgs<
|
|
635
|
+
* @param {(result: FaasData<Path>) => void} [args.onSuccess] - Optional callback invoked after a successful response.
|
|
636
|
+
* @param {UseFaasRequestArgs<Path>['send']} args.send - Transport function responsible for creating and resolving the request.
|
|
638
637
|
* @returns Shared request state, reload helpers, and refs used by `useFaas` and `useFaasStream`.
|
|
639
638
|
* @example
|
|
640
639
|
* ```ts
|
|
@@ -833,13 +832,13 @@ function useFaasRequest({ action, defaultParams, options, beforeSend, onSuccess,
|
|
|
833
832
|
* It sends an initial request unless `skip` is enabled, and returns request state
|
|
834
833
|
* plus helpers for reloading, background refreshing, updating data, and handling errors.
|
|
835
834
|
*
|
|
836
|
-
* @template
|
|
835
|
+
* @template Path - Action path or response data type used for inference.
|
|
837
836
|
*
|
|
838
|
-
* @param {
|
|
839
|
-
* @param {FaasParams<
|
|
840
|
-
* @param {UseFaasOptions<
|
|
837
|
+
* @param {Path} action - Action path to invoke.
|
|
838
|
+
* @param {FaasParams<Path>} defaultParams - Params used for the initial request and future reloads.
|
|
839
|
+
* @param {UseFaasOptions<Path>} [options] - Optional hook configuration such as controlled data, skip logic, debounce timing, polling, and base URL overrides.
|
|
841
840
|
* See the `UseFaasOptions` type for `params`, `data`, `setData`, `skip`, `debounce`, `polling`, and `baseUrl`.
|
|
842
|
-
* @returns {FaasDataInjection<
|
|
841
|
+
* @returns {FaasDataInjection<Path>} Request state and helper methods described by {@link FaasDataInjection}.
|
|
843
842
|
*
|
|
844
843
|
* @example
|
|
845
844
|
* ```tsx
|
|
@@ -883,10 +882,10 @@ function useFaas(action, defaultParams, options = {}) {
|
|
|
883
882
|
if (options.setData) options.setData(nextData);
|
|
884
883
|
else localSetData(nextData);
|
|
885
884
|
},
|
|
886
|
-
send: ({ action, params, signal, client, setPromise }) => {
|
|
885
|
+
send: async ({ action, params, signal, client, setPromise }) => {
|
|
887
886
|
const promise = client.faas(action, params, { signal });
|
|
888
887
|
setPromise(promise);
|
|
889
|
-
return promise
|
|
888
|
+
return (await promise).data;
|
|
890
889
|
}
|
|
891
890
|
});
|
|
892
891
|
const currentData = options.data ?? data;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/react",
|
|
3
|
-
"version": "8.0.0-beta.
|
|
3
|
+
"version": "8.0.0-beta.30",
|
|
4
4
|
"homepage": "https://faasjs.com/doc/react/",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/faasjs/faasjs/issues"
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@faasjs/types": ">=8.0.0-beta.
|
|
29
|
+
"@faasjs/types": ">=8.0.0-beta.30",
|
|
30
30
|
"@types/react": "^19.0.0",
|
|
31
31
|
"react": "^19.0.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@faasjs/types": ">=8.0.0-beta.
|
|
34
|
+
"@faasjs/types": ">=8.0.0-beta.30"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=26.0.0",
|