@molecule/app-react 3.0.0 → 3.0.1
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
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-10-
|
|
6
|
+
Generated: 2026-10-28T08:44:20.660Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-react
|
|
@@ -2484,6 +2484,17 @@ function useProfileForm<TUser, TValues extends FormValuesConstraint<TValues>>(
|
|
|
2484
2484
|
|
|
2485
2485
|
Hook that wraps an async function with state tracking.
|
|
2486
2486
|
|
|
2487
|
+
For one UI action, pass `state.status === 'pending'` to `Button loading`
|
|
2488
|
+
from `@molecule/app-ui-react` (or to a native control's `disabled` prop).
|
|
2489
|
+
The control then refuses input while the request is pending and re-enables
|
|
2490
|
+
when the tracked call settles. Handle the returned promise's rejection;
|
|
2491
|
+
the hook also records the failure in `state.error`.
|
|
2492
|
+
|
|
2493
|
+
This hook tracks the latest call: it does not serialize invocations or
|
|
2494
|
+
cancel their network requests. An explicit reset/cancel changes the tracked
|
|
2495
|
+
state, so it is not proof that an outstanding request has stopped. Use an
|
|
2496
|
+
app-owned queue when every click must be accepted in order.
|
|
2497
|
+
|
|
2487
2498
|
```typescript
|
|
2488
2499
|
function usePromise<T extends (...args: any[]) => Promise<any>>(
|
|
2489
2500
|
asyncFn: T,
|
|
@@ -17,6 +17,17 @@ export interface UsePromiseState<T> {
|
|
|
17
17
|
/**
|
|
18
18
|
* Hook that wraps an async function with state tracking.
|
|
19
19
|
*
|
|
20
|
+
* For one UI action, pass `state.status === 'pending'` to `Button loading`
|
|
21
|
+
* from `@molecule/app-ui-react` (or to a native control's `disabled` prop).
|
|
22
|
+
* The control then refuses input while the request is pending and re-enables
|
|
23
|
+
* when the tracked call settles. Handle the returned promise's rejection;
|
|
24
|
+
* the hook also records the failure in `state.error`.
|
|
25
|
+
*
|
|
26
|
+
* This hook tracks the latest call: it does not serialize invocations or
|
|
27
|
+
* cancel their network requests. An explicit reset/cancel changes the tracked
|
|
28
|
+
* state, so it is not proof that an outstanding request has stopped. Use an
|
|
29
|
+
* app-owned queue when every click must be accepted in order.
|
|
30
|
+
*
|
|
20
31
|
* @param asyncFn - The async function to wrap
|
|
21
32
|
* @returns Tuple of [state, wrappedFunction]
|
|
22
33
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePromise.d.ts","sourceRoot":"","sources":["../../src/hooks/usePromise.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAE5D;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,MAAM,EAAE,aAAa,CAAA;IACrB,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;IACf,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB;AAED
|
|
1
|
+
{"version":3,"file":"usePromise.d.ts","sourceRoot":"","sources":["../../src/hooks/usePromise.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAE5D;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,MAAM,EAAE,aAAa,CAAA;IACrB,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;IACf,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EACnE,SAAS,CAAC,KACT,CACD,eAAe,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,EACvC,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CA+F5D,CAAA"}
|
package/dist/hooks/usePromise.js
CHANGED
|
@@ -8,6 +8,17 @@ import { useEffect, useMemo, useRef, useState } from 'react';
|
|
|
8
8
|
/**
|
|
9
9
|
* Hook that wraps an async function with state tracking.
|
|
10
10
|
*
|
|
11
|
+
* For one UI action, pass `state.status === 'pending'` to `Button loading`
|
|
12
|
+
* from `@molecule/app-ui-react` (or to a native control's `disabled` prop).
|
|
13
|
+
* The control then refuses input while the request is pending and re-enables
|
|
14
|
+
* when the tracked call settles. Handle the returned promise's rejection;
|
|
15
|
+
* the hook also records the failure in `state.error`.
|
|
16
|
+
*
|
|
17
|
+
* This hook tracks the latest call: it does not serialize invocations or
|
|
18
|
+
* cancel their network requests. An explicit reset/cancel changes the tracked
|
|
19
|
+
* state, so it is not proof that an outstanding request has stopped. Use an
|
|
20
|
+
* app-owned queue when every click must be accepted in order.
|
|
21
|
+
*
|
|
11
22
|
* @param asyncFn - The async function to wrap
|
|
12
23
|
* @returns Tuple of [state, wrappedFunction]
|
|
13
24
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePromise.js","sourceRoot":"","sources":["../../src/hooks/usePromise.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,uDAAuD;AACvD,OAAO,EAAE,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