floppy-disk 2.5.0-beta.1 → 2.5.0-beta.2

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
@@ -18,7 +18,7 @@ import {
18
18
  useInfiniteQuery,
19
19
  useMutation,
20
20
  } from '@tanstack/react-query'; // 41 kB (gzipped: 11 kB)
21
- import { createQuery, createMutation } from 'floppy-disk'; // 8.4 kB (gzipped: 2.8 kB) 🎉
21
+ import { createQuery, createMutation } from 'floppy-disk'; // 9.2 kB (gzipped: 3.1 kB) 🎉
22
22
  ```
23
23
 
24
24
  - Using Zustand & React-Query: https://demo-zustand-react-query.vercel.app/
@@ -641,7 +641,7 @@ const usePokemonsInfQuery = createQuery(
641
641
  throw res;
642
642
  },
643
643
  {
644
- select: (response, { data }) => [...(data || []), ...response.results],
644
+ select: (response, { data = [] }) => [...data, ...response.results],
645
645
  getNextPageParam: (lastPageResponse, i) => {
646
646
  if (i > 5) return undefined; // Return undefined means you have reached the end of the pages
647
647
  return i * 10;
@@ -650,11 +650,11 @@ const usePokemonsInfQuery = createQuery(
650
650
  );
651
651
 
652
652
  function PokemonListPage() {
653
- const { data, fetchNextPage, hasNextPage, isWaitingNextPage } = usePokemonsInfQuery();
653
+ const { data = [], fetchNextPage, hasNextPage, isWaitingNextPage } = usePokemonsInfQuery();
654
654
 
655
655
  return (
656
656
  <div>
657
- {data?.map((pokemon) => (
657
+ {data.map((pokemon) => (
658
658
  <div key={pokemon.name}>{pokemon.name}</div>
659
659
  ))}
660
660
  {isWaitingNextPage ? (
@@ -7,9 +7,9 @@ export type MutationState<TVar, TResponse = any, TError = unknown> = {
7
7
  isWaiting: boolean;
8
8
  isSuccess: boolean;
9
9
  isError: boolean;
10
- response: TResponse | null;
10
+ response: TResponse | undefined;
11
11
  responseUpdatedAt: number | null;
12
- error: TError | null;
12
+ error: TError | undefined;
13
13
  errorUpdatedAt: number | null;
14
14
  /**
15
15
  * Mutate function.
@@ -9,9 +9,9 @@ export const createMutation = (mutationFn, options = {}) => {
9
9
  isWaiting: false,
10
10
  isSuccess: false,
11
11
  isError: false,
12
- response: null,
12
+ response: undefined,
13
13
  responseUpdatedAt: null,
14
- error: null,
14
+ error: undefined,
15
15
  errorUpdatedAt: null,
16
16
  mutate: ((variables) => {
17
17
  set({ isWaiting: true });
@@ -26,7 +26,7 @@ export const createMutation = (mutationFn, options = {}) => {
26
26
  isError: false,
27
27
  response,
28
28
  responseUpdatedAt: Date.now(),
29
- error: null,
29
+ error: undefined,
30
30
  errorUpdatedAt: null,
31
31
  });
32
32
  onSuccess(response, variables, stateBeforeMutate);
@@ -57,7 +57,7 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
57
57
  isRefetchError: boolean;
58
58
  isPreviousData: boolean;
59
59
  isOptimisticData: boolean;
60
- error: TError | null;
60
+ error: TError | undefined;
61
61
  errorUpdatedAt: number | null;
62
62
  retryCount: number;
63
63
  isGoingToRetry: boolean;
@@ -99,8 +99,8 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
99
99
  * If data fetched successfully but then an error occured, `isError` will be `false` but `isRefetchError` will be `true`.
100
100
  */
101
101
  isError: false;
102
- data: null;
103
- response: null;
102
+ data: undefined;
103
+ response: undefined;
104
104
  responseUpdatedAt: null;
105
105
  } | {
106
106
  status: 'success';
@@ -115,8 +115,8 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
115
115
  isLoading: false;
116
116
  isSuccess: false;
117
117
  isError: true;
118
- data: null;
119
- response: null;
118
+ data: undefined;
119
+ response: undefined;
120
120
  responseUpdatedAt: null;
121
121
  });
122
122
  export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = CreateStoresOptions<TKey, QueryState<TKey, TResponse, TData, TError>> & {
@@ -13,10 +13,10 @@ const INITIAL_QUERY_STATE = {
13
13
  isRefetchError: false,
14
14
  isPreviousData: false,
15
15
  isOptimisticData: false,
16
- data: null,
17
- response: null,
16
+ data: undefined,
17
+ response: undefined,
18
18
  responseUpdatedAt: null,
19
- error: null,
19
+ error: undefined,
20
20
  errorUpdatedAt: null,
21
21
  retryCount: 0,
22
22
  isGoingToRetry: false,
@@ -109,10 +109,10 @@ export const createQuery = (queryFn, options = {}) => {
109
109
  isOptimisticData: false,
110
110
  data: responseAllPages.reduce((prev, responseCurrentPage) => {
111
111
  return select(responseCurrentPage, { key, data: prev });
112
- }, null),
112
+ }, undefined),
113
113
  response,
114
114
  responseUpdatedAt: Date.now(),
115
- error: null,
115
+ error: undefined,
116
116
  errorUpdatedAt: null,
117
117
  retryCount: 0,
118
118
  pageParam: newPageParam,
@@ -128,7 +128,6 @@ export const createQuery = (queryFn, options = {}) => {
128
128
  }
129
129
  set(nextState);
130
130
  onSuccess(response, stateBeforeCallQuery);
131
- resolve(get());
132
131
  })
133
132
  .catch((error) => {
134
133
  const prevState = get();
@@ -142,7 +141,7 @@ export const createQuery = (queryFn, options = {}) => {
142
141
  data: responseAllPages.length
143
142
  ? responseAllPages.reduce((prev, response) => {
144
143
  return select(response, { key, data: prev });
145
- }, null)
144
+ }, undefined)
146
145
  : prevState.data,
147
146
  error,
148
147
  errorUpdatedAt,
@@ -155,7 +154,7 @@ export const createQuery = (queryFn, options = {}) => {
155
154
  status: 'error',
156
155
  isLoading: false,
157
156
  isError: true,
158
- data: null,
157
+ data: undefined,
159
158
  error,
160
159
  errorUpdatedAt,
161
160
  isGoingToRetry: shouldRetry,
@@ -169,10 +168,10 @@ export const createQuery = (queryFn, options = {}) => {
169
168
  }, delay));
170
169
  }
171
170
  onError(error, stateBeforeCallQuery);
172
- resolve(get());
173
171
  })
174
172
  .finally(() => {
175
173
  onSettled(stateBeforeCallQuery);
174
+ resolve(get());
176
175
  });
177
176
  };
178
177
  callQuery();
@@ -218,7 +217,6 @@ export const createQuery = (queryFn, options = {}) => {
218
217
  hasNextPage: hasValue(newPageParam),
219
218
  });
220
219
  onSuccess(response, stateBeforeCallQuery);
221
- resolve(get());
222
220
  })
223
221
  .catch((error) => {
224
222
  const prevState = get();
@@ -237,10 +235,10 @@ export const createQuery = (queryFn, options = {}) => {
237
235
  }, delay));
238
236
  }
239
237
  onError(error, stateBeforeCallQuery);
240
- resolve(get());
241
238
  })
242
239
  .finally(() => {
243
240
  onSettled(stateBeforeCallQuery);
241
+ resolve(get());
244
242
  });
245
243
  });
246
244
  return {
@@ -339,7 +337,7 @@ export const createQuery = (queryFn, options = {}) => {
339
337
  isError: false,
340
338
  response,
341
339
  responseUpdatedAt: skipRevalidation ? Date.now() : null,
342
- data: select(response, { key: key, data: null }),
340
+ data: select(response, { key: key, data: undefined }),
343
341
  pageParam: newPageParam,
344
342
  pageParams: [undefined, newPageParam],
345
343
  hasNextPage: hasValue(newPageParam),
@@ -377,7 +375,7 @@ export const createQuery = (queryFn, options = {}) => {
377
375
  useQuery.set(key, {
378
376
  isOptimisticData: true,
379
377
  response: optimisticResponse,
380
- data: select(optimisticResponse, { key: key, data: null }),
378
+ data: select(optimisticResponse, { key: key, data: undefined }),
381
379
  });
382
380
  preventReplaceResponse.set(prevState.keyHash, true);
383
381
  const revert = () => {
@@ -7,9 +7,9 @@ export type MutationState<TVar, TResponse = any, TError = unknown> = {
7
7
  isWaiting: boolean;
8
8
  isSuccess: boolean;
9
9
  isError: boolean;
10
- response: TResponse | null;
10
+ response: TResponse | undefined;
11
11
  responseUpdatedAt: number | null;
12
- error: TError | null;
12
+ error: TError | undefined;
13
13
  errorUpdatedAt: number | null;
14
14
  /**
15
15
  * Mutate function.
@@ -9,9 +9,9 @@ export const createMutation = (mutationFn, options = {}) => {
9
9
  isWaiting: false,
10
10
  isSuccess: false,
11
11
  isError: false,
12
- response: null,
12
+ response: undefined,
13
13
  responseUpdatedAt: null,
14
- error: null,
14
+ error: undefined,
15
15
  errorUpdatedAt: null,
16
16
  mutate: ((variables) => {
17
17
  set({ isWaiting: true });
@@ -26,7 +26,7 @@ export const createMutation = (mutationFn, options = {}) => {
26
26
  isError: false,
27
27
  response,
28
28
  responseUpdatedAt: Date.now(),
29
- error: null,
29
+ error: undefined,
30
30
  errorUpdatedAt: null,
31
31
  });
32
32
  onSuccess(response, variables, stateBeforeMutate);
@@ -56,7 +56,7 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
56
56
  isRefetchError: boolean;
57
57
  isPreviousData: boolean;
58
58
  isOptimisticData: boolean;
59
- error: TError | null;
59
+ error: TError | undefined;
60
60
  errorUpdatedAt: number | null;
61
61
  retryCount: number;
62
62
  isGoingToRetry: boolean;
@@ -98,8 +98,8 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
98
98
  * If data fetched successfully but then an error occured, `isError` will be `false` but `isRefetchError` will be `true`.
99
99
  */
100
100
  isError: false;
101
- data: null;
102
- response: null;
101
+ data: undefined;
102
+ response: undefined;
103
103
  responseUpdatedAt: null;
104
104
  } | {
105
105
  status: 'success';
@@ -114,8 +114,8 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
114
114
  isLoading: false;
115
115
  isSuccess: false;
116
116
  isError: true;
117
- data: null;
118
- response: null;
117
+ data: undefined;
118
+ response: undefined;
119
119
  responseUpdatedAt: null;
120
120
  });
121
121
  export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = CreateStoresOptions<TKey, QueryState<TKey, TResponse, TData, TError>> & {
@@ -12,10 +12,10 @@ const INITIAL_QUERY_STATE = {
12
12
  isRefetchError: false,
13
13
  isPreviousData: false,
14
14
  isOptimisticData: false,
15
- data: null,
16
- response: null,
15
+ data: undefined,
16
+ response: undefined,
17
17
  responseUpdatedAt: null,
18
- error: null,
18
+ error: undefined,
19
19
  errorUpdatedAt: null,
20
20
  retryCount: 0,
21
21
  isGoingToRetry: false,
@@ -108,10 +108,10 @@ export const createQuery = (queryFn, options = {}) => {
108
108
  isOptimisticData: false,
109
109
  data: responseAllPages.reduce((prev, responseCurrentPage) => {
110
110
  return select(responseCurrentPage, { key, data: prev });
111
- }, null),
111
+ }, undefined),
112
112
  response,
113
113
  responseUpdatedAt: Date.now(),
114
- error: null,
114
+ error: undefined,
115
115
  errorUpdatedAt: null,
116
116
  retryCount: 0,
117
117
  pageParam: newPageParam,
@@ -127,7 +127,6 @@ export const createQuery = (queryFn, options = {}) => {
127
127
  }
128
128
  set(nextState);
129
129
  onSuccess(response, stateBeforeCallQuery);
130
- resolve(get());
131
130
  })
132
131
  .catch((error) => {
133
132
  const prevState = get();
@@ -141,7 +140,7 @@ export const createQuery = (queryFn, options = {}) => {
141
140
  data: responseAllPages.length
142
141
  ? responseAllPages.reduce((prev, response) => {
143
142
  return select(response, { key, data: prev });
144
- }, null)
143
+ }, undefined)
145
144
  : prevState.data,
146
145
  error,
147
146
  errorUpdatedAt,
@@ -154,7 +153,7 @@ export const createQuery = (queryFn, options = {}) => {
154
153
  status: 'error',
155
154
  isLoading: false,
156
155
  isError: true,
157
- data: null,
156
+ data: undefined,
158
157
  error,
159
158
  errorUpdatedAt,
160
159
  isGoingToRetry: shouldRetry,
@@ -168,10 +167,10 @@ export const createQuery = (queryFn, options = {}) => {
168
167
  }, delay));
169
168
  }
170
169
  onError(error, stateBeforeCallQuery);
171
- resolve(get());
172
170
  })
173
171
  .finally(() => {
174
172
  onSettled(stateBeforeCallQuery);
173
+ resolve(get());
175
174
  });
176
175
  };
177
176
  callQuery();
@@ -217,7 +216,6 @@ export const createQuery = (queryFn, options = {}) => {
217
216
  hasNextPage: hasValue(newPageParam),
218
217
  });
219
218
  onSuccess(response, stateBeforeCallQuery);
220
- resolve(get());
221
219
  })
222
220
  .catch((error) => {
223
221
  const prevState = get();
@@ -236,10 +234,10 @@ export const createQuery = (queryFn, options = {}) => {
236
234
  }, delay));
237
235
  }
238
236
  onError(error, stateBeforeCallQuery);
239
- resolve(get());
240
237
  })
241
238
  .finally(() => {
242
239
  onSettled(stateBeforeCallQuery);
240
+ resolve(get());
243
241
  });
244
242
  });
245
243
  return {
@@ -338,7 +336,7 @@ export const createQuery = (queryFn, options = {}) => {
338
336
  isError: false,
339
337
  response,
340
338
  responseUpdatedAt: skipRevalidation ? Date.now() : null,
341
- data: select(response, { key: key, data: null }),
339
+ data: select(response, { key: key, data: undefined }),
342
340
  pageParam: newPageParam,
343
341
  pageParams: [undefined, newPageParam],
344
342
  hasNextPage: hasValue(newPageParam),
@@ -376,7 +374,7 @@ export const createQuery = (queryFn, options = {}) => {
376
374
  useQuery.set(key, {
377
375
  isOptimisticData: true,
378
376
  response: optimisticResponse,
379
- data: select(optimisticResponse, { key: key, data: null }),
377
+ data: select(optimisticResponse, { key: key, data: undefined }),
380
378
  });
381
379
  preventReplaceResponse.set(prevState.keyHash, true);
382
380
  const revert = () => {
@@ -7,9 +7,9 @@ export type MutationState<TVar, TResponse = any, TError = unknown> = {
7
7
  isWaiting: boolean;
8
8
  isSuccess: boolean;
9
9
  isError: boolean;
10
- response: TResponse | null;
10
+ response: TResponse | undefined;
11
11
  responseUpdatedAt: number | null;
12
- error: TError | null;
12
+ error: TError | undefined;
13
13
  errorUpdatedAt: number | null;
14
14
  /**
15
15
  * Mutate function.
@@ -12,9 +12,9 @@ const createMutation = (mutationFn, options = {}) => {
12
12
  isWaiting: false,
13
13
  isSuccess: false,
14
14
  isError: false,
15
- response: null,
15
+ response: undefined,
16
16
  responseUpdatedAt: null,
17
- error: null,
17
+ error: undefined,
18
18
  errorUpdatedAt: null,
19
19
  mutate: ((variables) => {
20
20
  set({ isWaiting: true });
@@ -29,7 +29,7 @@ const createMutation = (mutationFn, options = {}) => {
29
29
  isError: false,
30
30
  response,
31
31
  responseUpdatedAt: Date.now(),
32
- error: null,
32
+ error: undefined,
33
33
  errorUpdatedAt: null,
34
34
  });
35
35
  onSuccess(response, variables, stateBeforeMutate);
@@ -57,7 +57,7 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
57
57
  isRefetchError: boolean;
58
58
  isPreviousData: boolean;
59
59
  isOptimisticData: boolean;
60
- error: TError | null;
60
+ error: TError | undefined;
61
61
  errorUpdatedAt: number | null;
62
62
  retryCount: number;
63
63
  isGoingToRetry: boolean;
@@ -99,8 +99,8 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
99
99
  * If data fetched successfully but then an error occured, `isError` will be `false` but `isRefetchError` will be `true`.
100
100
  */
101
101
  isError: false;
102
- data: null;
103
- response: null;
102
+ data: undefined;
103
+ response: undefined;
104
104
  responseUpdatedAt: null;
105
105
  } | {
106
106
  status: 'success';
@@ -115,8 +115,8 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
115
115
  isLoading: false;
116
116
  isSuccess: false;
117
117
  isError: true;
118
- data: null;
119
- response: null;
118
+ data: undefined;
119
+ response: undefined;
120
120
  responseUpdatedAt: null;
121
121
  });
122
122
  export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = CreateStoresOptions<TKey, QueryState<TKey, TResponse, TData, TError>> & {
@@ -16,10 +16,10 @@ const INITIAL_QUERY_STATE = {
16
16
  isRefetchError: false,
17
17
  isPreviousData: false,
18
18
  isOptimisticData: false,
19
- data: null,
20
- response: null,
19
+ data: undefined,
20
+ response: undefined,
21
21
  responseUpdatedAt: null,
22
- error: null,
22
+ error: undefined,
23
23
  errorUpdatedAt: null,
24
24
  retryCount: 0,
25
25
  isGoingToRetry: false,
@@ -112,10 +112,10 @@ const createQuery = (queryFn, options = {}) => {
112
112
  isOptimisticData: false,
113
113
  data: responseAllPages.reduce((prev, responseCurrentPage) => {
114
114
  return select(responseCurrentPage, { key, data: prev });
115
- }, null),
115
+ }, undefined),
116
116
  response,
117
117
  responseUpdatedAt: Date.now(),
118
- error: null,
118
+ error: undefined,
119
119
  errorUpdatedAt: null,
120
120
  retryCount: 0,
121
121
  pageParam: newPageParam,
@@ -131,7 +131,6 @@ const createQuery = (queryFn, options = {}) => {
131
131
  }
132
132
  set(nextState);
133
133
  onSuccess(response, stateBeforeCallQuery);
134
- resolve(get());
135
134
  })
136
135
  .catch((error) => {
137
136
  const prevState = get();
@@ -145,7 +144,7 @@ const createQuery = (queryFn, options = {}) => {
145
144
  data: responseAllPages.length
146
145
  ? responseAllPages.reduce((prev, response) => {
147
146
  return select(response, { key, data: prev });
148
- }, null)
147
+ }, undefined)
149
148
  : prevState.data,
150
149
  error,
151
150
  errorUpdatedAt,
@@ -158,7 +157,7 @@ const createQuery = (queryFn, options = {}) => {
158
157
  status: 'error',
159
158
  isLoading: false,
160
159
  isError: true,
161
- data: null,
160
+ data: undefined,
162
161
  error,
163
162
  errorUpdatedAt,
164
163
  isGoingToRetry: shouldRetry,
@@ -172,10 +171,10 @@ const createQuery = (queryFn, options = {}) => {
172
171
  }, delay));
173
172
  }
174
173
  onError(error, stateBeforeCallQuery);
175
- resolve(get());
176
174
  })
177
175
  .finally(() => {
178
176
  onSettled(stateBeforeCallQuery);
177
+ resolve(get());
179
178
  });
180
179
  };
181
180
  callQuery();
@@ -221,7 +220,6 @@ const createQuery = (queryFn, options = {}) => {
221
220
  hasNextPage: (0, utils_1.hasValue)(newPageParam),
222
221
  });
223
222
  onSuccess(response, stateBeforeCallQuery);
224
- resolve(get());
225
223
  })
226
224
  .catch((error) => {
227
225
  const prevState = get();
@@ -240,10 +238,10 @@ const createQuery = (queryFn, options = {}) => {
240
238
  }, delay));
241
239
  }
242
240
  onError(error, stateBeforeCallQuery);
243
- resolve(get());
244
241
  })
245
242
  .finally(() => {
246
243
  onSettled(stateBeforeCallQuery);
244
+ resolve(get());
247
245
  });
248
246
  });
249
247
  return {
@@ -342,7 +340,7 @@ const createQuery = (queryFn, options = {}) => {
342
340
  isError: false,
343
341
  response,
344
342
  responseUpdatedAt: skipRevalidation ? Date.now() : null,
345
- data: select(response, { key: key, data: null }),
343
+ data: select(response, { key: key, data: undefined }),
346
344
  pageParam: newPageParam,
347
345
  pageParams: [undefined, newPageParam],
348
346
  hasNextPage: (0, utils_1.hasValue)(newPageParam),
@@ -380,7 +378,7 @@ const createQuery = (queryFn, options = {}) => {
380
378
  useQuery.set(key, {
381
379
  isOptimisticData: true,
382
380
  response: optimisticResponse,
383
- data: select(optimisticResponse, { key: key, data: null }),
381
+ data: select(optimisticResponse, { key: key, data: undefined }),
384
382
  });
385
383
  preventReplaceResponse.set(prevState.keyHash, true);
386
384
  const revert = () => {
@@ -7,9 +7,9 @@ export type MutationState<TVar, TResponse = any, TError = unknown> = {
7
7
  isWaiting: boolean;
8
8
  isSuccess: boolean;
9
9
  isError: boolean;
10
- response: TResponse | null;
10
+ response: TResponse | undefined;
11
11
  responseUpdatedAt: number | null;
12
- error: TError | null;
12
+ error: TError | undefined;
13
13
  errorUpdatedAt: number | null;
14
14
  /**
15
15
  * Mutate function.
@@ -12,9 +12,9 @@ const createMutation = (mutationFn, options = {}) => {
12
12
  isWaiting: false,
13
13
  isSuccess: false,
14
14
  isError: false,
15
- response: null,
15
+ response: undefined,
16
16
  responseUpdatedAt: null,
17
- error: null,
17
+ error: undefined,
18
18
  errorUpdatedAt: null,
19
19
  mutate: ((variables) => {
20
20
  set({ isWaiting: true });
@@ -29,7 +29,7 @@ const createMutation = (mutationFn, options = {}) => {
29
29
  isError: false,
30
30
  response,
31
31
  responseUpdatedAt: Date.now(),
32
- error: null,
32
+ error: undefined,
33
33
  errorUpdatedAt: null,
34
34
  });
35
35
  onSuccess(response, variables, stateBeforeMutate);
@@ -56,7 +56,7 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
56
56
  isRefetchError: boolean;
57
57
  isPreviousData: boolean;
58
58
  isOptimisticData: boolean;
59
- error: TError | null;
59
+ error: TError | undefined;
60
60
  errorUpdatedAt: number | null;
61
61
  retryCount: number;
62
62
  isGoingToRetry: boolean;
@@ -98,8 +98,8 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
98
98
  * If data fetched successfully but then an error occured, `isError` will be `false` but `isRefetchError` will be `true`.
99
99
  */
100
100
  isError: false;
101
- data: null;
102
- response: null;
101
+ data: undefined;
102
+ response: undefined;
103
103
  responseUpdatedAt: null;
104
104
  } | {
105
105
  status: 'success';
@@ -114,8 +114,8 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
114
114
  isLoading: false;
115
115
  isSuccess: false;
116
116
  isError: true;
117
- data: null;
118
- response: null;
117
+ data: undefined;
118
+ response: undefined;
119
119
  responseUpdatedAt: null;
120
120
  });
121
121
  export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = CreateStoresOptions<TKey, QueryState<TKey, TResponse, TData, TError>> & {
@@ -15,10 +15,10 @@ const INITIAL_QUERY_STATE = {
15
15
  isRefetchError: false,
16
16
  isPreviousData: false,
17
17
  isOptimisticData: false,
18
- data: null,
19
- response: null,
18
+ data: undefined,
19
+ response: undefined,
20
20
  responseUpdatedAt: null,
21
- error: null,
21
+ error: undefined,
22
22
  errorUpdatedAt: null,
23
23
  retryCount: 0,
24
24
  isGoingToRetry: false,
@@ -111,10 +111,10 @@ const createQuery = (queryFn, options = {}) => {
111
111
  isOptimisticData: false,
112
112
  data: responseAllPages.reduce((prev, responseCurrentPage) => {
113
113
  return select(responseCurrentPage, { key, data: prev });
114
- }, null),
114
+ }, undefined),
115
115
  response,
116
116
  responseUpdatedAt: Date.now(),
117
- error: null,
117
+ error: undefined,
118
118
  errorUpdatedAt: null,
119
119
  retryCount: 0,
120
120
  pageParam: newPageParam,
@@ -130,7 +130,6 @@ const createQuery = (queryFn, options = {}) => {
130
130
  }
131
131
  set(nextState);
132
132
  onSuccess(response, stateBeforeCallQuery);
133
- resolve(get());
134
133
  })
135
134
  .catch((error) => {
136
135
  const prevState = get();
@@ -144,7 +143,7 @@ const createQuery = (queryFn, options = {}) => {
144
143
  data: responseAllPages.length
145
144
  ? responseAllPages.reduce((prev, response) => {
146
145
  return select(response, { key, data: prev });
147
- }, null)
146
+ }, undefined)
148
147
  : prevState.data,
149
148
  error,
150
149
  errorUpdatedAt,
@@ -157,7 +156,7 @@ const createQuery = (queryFn, options = {}) => {
157
156
  status: 'error',
158
157
  isLoading: false,
159
158
  isError: true,
160
- data: null,
159
+ data: undefined,
161
160
  error,
162
161
  errorUpdatedAt,
163
162
  isGoingToRetry: shouldRetry,
@@ -171,10 +170,10 @@ const createQuery = (queryFn, options = {}) => {
171
170
  }, delay));
172
171
  }
173
172
  onError(error, stateBeforeCallQuery);
174
- resolve(get());
175
173
  })
176
174
  .finally(() => {
177
175
  onSettled(stateBeforeCallQuery);
176
+ resolve(get());
178
177
  });
179
178
  };
180
179
  callQuery();
@@ -220,7 +219,6 @@ const createQuery = (queryFn, options = {}) => {
220
219
  hasNextPage: (0, utils_1.hasValue)(newPageParam),
221
220
  });
222
221
  onSuccess(response, stateBeforeCallQuery);
223
- resolve(get());
224
222
  })
225
223
  .catch((error) => {
226
224
  const prevState = get();
@@ -239,10 +237,10 @@ const createQuery = (queryFn, options = {}) => {
239
237
  }, delay));
240
238
  }
241
239
  onError(error, stateBeforeCallQuery);
242
- resolve(get());
243
240
  })
244
241
  .finally(() => {
245
242
  onSettled(stateBeforeCallQuery);
243
+ resolve(get());
246
244
  });
247
245
  });
248
246
  return {
@@ -341,7 +339,7 @@ const createQuery = (queryFn, options = {}) => {
341
339
  isError: false,
342
340
  response,
343
341
  responseUpdatedAt: skipRevalidation ? Date.now() : null,
344
- data: select(response, { key: key, data: null }),
342
+ data: select(response, { key: key, data: undefined }),
345
343
  pageParam: newPageParam,
346
344
  pageParams: [undefined, newPageParam],
347
345
  hasNextPage: (0, utils_1.hasValue)(newPageParam),
@@ -379,7 +377,7 @@ const createQuery = (queryFn, options = {}) => {
379
377
  useQuery.set(key, {
380
378
  isOptimisticData: true,
381
379
  response: optimisticResponse,
382
- data: select(optimisticResponse, { key: key, data: null }),
380
+ data: select(optimisticResponse, { key: key, data: undefined }),
383
381
  });
384
382
  preventReplaceResponse.set(prevState.keyHash, true);
385
383
  const revert = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floppy-disk",
3
- "version": "2.5.0-beta.1",
3
+ "version": "2.5.0-beta.2",
4
4
  "description": "FloppyDisk - lightweight, simple, and powerful state management library",
5
5
  "keywords": [
6
6
  "state",