qortex-react 0.3.0-beta.4 → 0.3.0-beta.6

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.
Files changed (2) hide show
  1. package/index.d.ts +74 -17
  2. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -2,9 +2,34 @@ import { Fetcher, QueryKey, QueryOptions, InferFetcherResult, QueryState } from
2
2
  export * from 'qortex-core';
3
3
 
4
4
  /**
5
- * useQuery hook for React integration with qortex
6
- * Provides reactive data fetching with automatic re-renders on state changes
7
- * Enhanced with automatic type inference from fetchers
5
+ * React hook for reactive data fetching with automatic re-renders on state changes
6
+ *
7
+ * @param key - Unique identifier for the query (string or array of primitives)
8
+ * @param opts - Query configuration options
9
+ * @param opts.fetcher - Async function that fetches data for this query
10
+ * @param opts.enabled - Whether the query should be active (default: true)
11
+ * @param opts.staleTime - Time in ms before data is considered stale (default: 0)
12
+ * @param opts.equalityStrategy - How to compare data for changes ('shallow' | 'deep')
13
+ * @param opts.equalityFn - Custom equality function for data comparison
14
+ * @param opts.refetchOnSubscribe - When to refetch on subscription ('always' | 'stale' | false)
15
+ * @param opts.placeholderData - Initial data to show while loading
16
+ * @param opts.usePreviousDataOnError - Keep previous data when error occurs
17
+ * @param opts.usePlaceholderOnError - Use placeholder data when error occurs
18
+ * @returns QueryState object with data, error, status, and computed flags
19
+ *
20
+ * Returns an object containing:
21
+ * - data: The current data value
22
+ * - error: Any error that occurred during fetching
23
+ * - status: Current status ('idle' | 'fetching' | 'success' | 'error')
24
+ * - isStale: Whether the data is considered stale
25
+ * - isLoading: Whether the query is currently loading
26
+ * - isFetching: Whether a fetch is in progress
27
+ * - isError: Whether the query is in an error state
28
+ * - isSuccess: Whether the query completed successfully
29
+ * - refetch: Function to manually trigger a refetch
30
+ *
31
+ * Automatically subscribes to query state changes and triggers re-renders when the state updates.
32
+ * Enhanced with automatic type inference from fetcher functions. Handles mount logic to potentially start fetching.
8
33
  */
9
34
  declare function useQuery<F extends Fetcher>(key: QueryKey, opts: QueryOptions<InferFetcherResult<F>> & {
10
35
  fetcher: F;
@@ -12,9 +37,25 @@ declare function useQuery<F extends Fetcher>(key: QueryKey, opts: QueryOptions<I
12
37
  declare function useQuery<T = any>(key: QueryKey, opts?: QueryOptions<T>): QueryState<T>;
13
38
 
14
39
  /**
15
- * useQueryData hook for React integration with qortex
16
- * Provides reactive data fetching with automatic re-renders on state changes
17
- * Enhanced with automatic type inference from fetchers
40
+ * React hook for reactive data fetching that returns only the data value
41
+ *
42
+ * @param key - Unique identifier for the query (string or array of primitives)
43
+ * @param opts - Query configuration options
44
+ * @param opts.fetcher - Async function that fetches data for this query
45
+ * @param opts.enabled - Whether the query should be active (default: true)
46
+ * @param opts.staleTime - Time in ms before data is considered stale (default: 0)
47
+ * @param opts.equalityStrategy - How to compare data for changes ('shallow' | 'deep')
48
+ * @param opts.equalityFn - Custom equality function for data comparison
49
+ * @param opts.refetchOnSubscribe - When to refetch on subscription ('always' | 'stale' | false)
50
+ * @param opts.placeholderData - Initial data to show while loading
51
+ * @param opts.usePreviousDataOnError - Keep previous data when error occurs
52
+ * @param opts.usePlaceholderOnError - Use placeholder data when error occurs
53
+ * @returns The current data value or undefined if not available
54
+ *
55
+ * Similar to useQuery but returns only the data value instead of the full QueryState object.
56
+ * Returns undefined if the query has never been fetched, is loading, or if an error occurred.
57
+ * Automatically subscribes to query state changes and triggers re-renders when the data updates.
58
+ * Enhanced with automatic type inference from fetcher functions. Handles mount logic to potentially start fetching.
18
59
  */
19
60
  declare function useQueryData<F extends Fetcher>(key: QueryKey, opts: QueryOptions<InferFetcherResult<F>> & {
20
61
  fetcher: F;
@@ -22,20 +63,36 @@ declare function useQueryData<F extends Fetcher>(key: QueryKey, opts: QueryOptio
22
63
  declare function useQueryData<T = any>(key: QueryKey, opts?: QueryOptions<T>): T | undefined;
23
64
 
24
65
  /**
25
- * useQuerySelect hook for React integration with qortex
26
- * Provides reactive data fetching with automatic re-renders on state changes
27
- * Enhanced with automatic type inference from fetchers
66
+ * React hook for reactive data fetching with smart subscription optimization
28
67
  *
29
- * Now includes smart subscription: automatically detects which properties are accessed
30
- * and only re-renders when those specific properties change, not the entire state.
68
+ * @param key - Unique identifier for the query (string or array of primitives)
69
+ * @param opts - Query configuration options
70
+ * @param opts.fetcher - Async function that fetches data for this query
71
+ * @param opts.enabled - Whether the query should be active (default: true)
72
+ * @param opts.staleTime - Time in ms before data is considered stale (default: 0)
73
+ * @param opts.equalityStrategy - How to compare data for changes ('shallow' | 'deep')
74
+ * @param opts.equalityFn - Custom equality function for data comparison
75
+ * @param opts.refetchOnSubscribe - When to refetch on subscription ('always' | 'stale' | false)
76
+ * @param opts.placeholderData - Initial data to show while loading
77
+ * @param opts.usePreviousDataOnError - Keep previous data when error occurs
78
+ * @param opts.usePlaceholderOnError - Use placeholder data when error occurs
79
+ * @returns QueryState object with data, error, status, and computed flags
31
80
  *
32
- * @example
33
- * ```tsx
34
- * const query = useQuerySelect('users', { fetcher: fetchUsers });
81
+ * Returns an object containing:
82
+ * - data: The current data value
83
+ * - error: Any error that occurred during fetching
84
+ * - status: Current status ('idle' | 'fetching' | 'success' | 'error')
85
+ * - isStale: Whether the data is considered stale
86
+ * - isLoading: Whether the query is currently loading
87
+ * - isFetching: Whether a fetch is in progress
88
+ * - isError: Whether the query is in an error state
89
+ * - isSuccess: Whether the query completed successfully
90
+ * - refetch: Function to manually trigger a refetch
35
91
  *
36
- * // Only re-renders when data or isSuccess changes, not when isError changes
37
- * return <div>{query.isSuccess ? query.data?.name : 'Loading...'}</div>;
38
- * ```
92
+ * Features smart subscription optimization: automatically detects which properties are accessed
93
+ * during render and only triggers re-renders when those specific properties change, not the entire state.
94
+ * This prevents unnecessary re-renders when unrelated properties change, improving performance.
95
+ * Enhanced with automatic type inference from fetcher functions. Handles mount logic to potentially start fetching.
39
96
  */
40
97
  declare function useQuerySelect<F extends Fetcher>(key: QueryKey, opts: QueryOptions<InferFetcherResult<F>> & {
41
98
  fetcher: F;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qortex-react",
3
- "version": "0.3.0-beta.4",
3
+ "version": "0.3.0-beta.6",
4
4
  "description": "React hook bridge for qortex runtime",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -50,7 +50,7 @@
50
50
  "author": "Darshan Naik",
51
51
  "license": "LGPL-3.0",
52
52
  "dependencies": {
53
- "qortex-core": "0.3.0-beta.4"
53
+ "qortex-core": "0.3.0-beta.6"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "react": ">=18"