* Returns the initial state of a query, based on its `initialData` and `initialDataUpdatedAt` * options. * @param options - The query options. * @returns The initial query state: `'success'` if `initialData` is set, otherwise `'pending'`.
( options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>, )
| 1088 | * @returns The initial query state: `'success'` if `initialData` is set, otherwise `'pending'`. |
| 1089 | */ |
| 1090 | function getDefaultState< |
| 1091 | TQueryFnData, |
| 1092 | TError, |
| 1093 | TData, |
| 1094 | TQueryKey extends QueryKey, |
| 1095 | >( |
| 1096 | options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>, |
| 1097 | ): QueryState<TData, TError> { |
| 1098 | const data = |
| 1099 | typeof options.initialData === 'function' |
| 1100 | ? (options.initialData as InitialDataFunction<TData>)() |
| 1101 | : options.initialData |
| 1102 | |
| 1103 | const hasData = data !== undefined |
| 1104 | |
| 1105 | const initialDataUpdatedAt = hasData |
| 1106 | ? typeof options.initialDataUpdatedAt === 'function' |
| 1107 | ? options.initialDataUpdatedAt() |
| 1108 | : options.initialDataUpdatedAt |
| 1109 | : 0 |
| 1110 | |
| 1111 | return { |
| 1112 | data, |
| 1113 | dataUpdateCount: 0, |
| 1114 | dataUpdatedAt: hasData ? (initialDataUpdatedAt ?? Date.now()) : 0, |
| 1115 | error: null, |
| 1116 | errorUpdateCount: 0, |
| 1117 | errorUpdatedAt: 0, |
| 1118 | fetchFailureCount: 0, |
| 1119 | fetchFailureReason: null, |
| 1120 | fetchMeta: null, |
| 1121 | isInvalidated: false, |
| 1122 | status: hasData ? 'success' : 'pending', |
| 1123 | fetchStatus: 'idle', |
| 1124 | } |
| 1125 | } |
no outgoing calls
no test coverage detected