@ahoo-wang/fetcher-react 3.3.9 → 3.4.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.
@@ -0,0 +1,72 @@
1
+ import { AutoExecuteCapable } from './types';
2
+ /**
3
+ * Configuration options for the useQueryState hook
4
+ * @template Q - The type of the query parameters
5
+ */
6
+ export interface UseQueryStateOptions<Q> extends AutoExecuteCapable {
7
+ /** The initial query parameters to be stored and managed */
8
+ initialQuery: Q;
9
+ /** Function to execute with the current query parameters. Called when autoExecute is true */
10
+ execute: (query: Q) => Promise<void>;
11
+ }
12
+ /**
13
+ * Return type of the useQueryState hook
14
+ * @template Q - The type of the query parameters
15
+ */
16
+ export interface UseQueryStateReturn<Q> {
17
+ /** Function to retrieve the current query parameters */
18
+ getQuery: () => Q;
19
+ /** Function to update the query parameters. Triggers execution if autoExecute is true */
20
+ setQuery: (query: Q) => void;
21
+ }
22
+ /**
23
+ * A React hook for managing query state with automatic execution capabilities
24
+ *
25
+ * This hook provides a centralized way to manage query parameters, including
26
+ * getting and setting the current query, and optionally automatically executing
27
+ * queries when the query changes or on component mount.
28
+ *
29
+ * @template Q - The type of the query parameters
30
+ * @param options - Configuration options for the hook
31
+ * @returns An object containing getQuery and setQuery functions
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * interface UserQuery {
36
+ * id: string;
37
+ * name?: string;
38
+ * }
39
+ *
40
+ * function UserComponent() {
41
+ * const executeQuery = async (query: UserQuery) => {
42
+ * // Perform query execution logic here
43
+ * console.log('Executing query:', query);
44
+ * };
45
+ *
46
+ * const { getQuery, setQuery } = useQueryState<UserQuery>({
47
+ * initialQuery: { id: '1' },
48
+ * autoExecute: true,
49
+ * execute: executeQuery,
50
+ * });
51
+ *
52
+ * const handleQueryChange = (newQuery: UserQuery) => {
53
+ * setQuery(newQuery); // Will automatically execute if autoExecute is true
54
+ * };
55
+ *
56
+ * const currentQuery = getQuery(); // Get current query parameters
57
+ *
58
+ * return (
59
+ * <div>
60
+ * <button onClick={() => handleQueryChange({ id: '2', name: 'John' })}>
61
+ * Update Query
62
+ * </button>
63
+ * </div>
64
+ * );
65
+ * }
66
+ * ```
67
+ *
68
+ * @throws This hook does not throw exceptions directly, but the execute function
69
+ * may throw exceptions that should be handled by the caller.
70
+ */
71
+ export declare function useQueryState<Q>(options: UseQueryStateOptions<Q>): UseQueryStateReturn<Q>;
72
+ //# sourceMappingURL=useQueryState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useQueryState.d.ts","sourceRoot":"","sources":["../../src/wow/useQueryState.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C;;;GAGG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC,CAAE,SAAQ,kBAAkB;IACjE,4DAA4D;IAC5D,YAAY,EAAE,CAAC,CAAC;IAChB,6FAA6F;IAC7F,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,wDAAwD;IACxD,QAAQ,EAAE,MAAM,CAAC,CAAC;IAClB,yFAAyF;IACzF,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAC/B,mBAAmB,CAAC,CAAC,CAAC,CA0BxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ahoo-wang/fetcher-react",
3
- "version": "3.3.9",
3
+ "version": "3.4.1",
4
4
  "description": "React integration for Fetcher HTTP client. Provides React Hooks and components for seamless data fetching with automatic re-rendering and loading states.",
5
5
  "keywords": [
6
6
  "fetch",
@@ -70,8 +70,8 @@
70
70
  "@testing-library/react": "^16.0.0",
71
71
  "@types/react": "^19.2.7",
72
72
  "@types/react-dom": "^19.2.3",
73
- "jsdom": "^27.2.0",
74
- "@vitejs/plugin-react": "^5.1.1"
73
+ "jsdom": "^27.3.0",
74
+ "@vitejs/plugin-react": "^5.1.2"
75
75
  },
76
76
  "scripts": {
77
77
  "build": "vite build",