@tanstack/preact-query 5.104.1 → 5.104.3
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/build/legacy/HydrationBoundary.cjs +2 -3
- package/build/legacy/HydrationBoundary.cjs.map +1 -1
- package/build/legacy/HydrationBoundary.d.cts +3 -4
- package/build/legacy/HydrationBoundary.d.cts.map +1 -1
- package/build/legacy/HydrationBoundary.d.ts +2 -3
- package/build/legacy/HydrationBoundary.d.ts.map +1 -1
- package/build/legacy/HydrationBoundary.js +2 -3
- package/build/legacy/HydrationBoundary.js.map +1 -1
- package/build/legacy/IsRestoringProvider.cjs +0 -1
- package/build/legacy/IsRestoringProvider.cjs.map +1 -1
- package/build/legacy/IsRestoringProvider.d.cts +0 -1
- package/build/legacy/IsRestoringProvider.d.cts.map +1 -1
- package/build/legacy/IsRestoringProvider.d.ts +0 -1
- package/build/legacy/IsRestoringProvider.d.ts.map +1 -1
- package/build/legacy/IsRestoringProvider.js +0 -1
- package/build/legacy/IsRestoringProvider.js.map +1 -1
- package/build/legacy/QueryClientProvider.cjs +3 -4
- package/build/legacy/QueryClientProvider.cjs.map +1 -1
- package/build/legacy/QueryClientProvider.d.cts +4 -5
- package/build/legacy/QueryClientProvider.d.cts.map +1 -1
- package/build/legacy/QueryClientProvider.d.ts +3 -4
- package/build/legacy/QueryClientProvider.d.ts.map +1 -1
- package/build/legacy/QueryClientProvider.js +3 -4
- package/build/legacy/QueryClientProvider.js.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.cjs +6 -4
- package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.cts +5 -5
- package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.ts +5 -5
- package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.js +6 -4
- package/build/legacy/QueryErrorResetBoundary.js.map +1 -1
- package/build/legacy/errorBoundaryUtils.cjs +21 -0
- package/build/legacy/errorBoundaryUtils.cjs.map +1 -1
- package/build/legacy/errorBoundaryUtils.d.cts +21 -0
- package/build/legacy/errorBoundaryUtils.d.cts.map +1 -1
- package/build/legacy/errorBoundaryUtils.d.ts +21 -0
- package/build/legacy/errorBoundaryUtils.d.ts.map +1 -1
- package/build/legacy/errorBoundaryUtils.js +21 -0
- package/build/legacy/errorBoundaryUtils.js.map +1 -1
- package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.cts +5 -16
- package/build/legacy/infiniteQueryOptions.d.cts.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.ts +5 -16
- package/build/legacy/infiniteQueryOptions.d.ts.map +1 -1
- package/build/legacy/infiniteQueryOptions.js.map +1 -1
- package/build/legacy/mutationOptions.cjs.map +1 -1
- package/build/legacy/mutationOptions.d.cts +2 -6
- package/build/legacy/mutationOptions.d.cts.map +1 -1
- package/build/legacy/mutationOptions.d.ts +2 -6
- package/build/legacy/mutationOptions.d.ts.map +1 -1
- package/build/legacy/mutationOptions.js.map +1 -1
- package/build/legacy/queryOptions.cjs.map +1 -1
- package/build/legacy/queryOptions.d.cts +6 -16
- package/build/legacy/queryOptions.d.cts.map +1 -1
- package/build/legacy/queryOptions.d.ts +6 -16
- package/build/legacy/queryOptions.d.ts.map +1 -1
- package/build/legacy/queryOptions.js.map +1 -1
- package/build/legacy/suspense.cjs +27 -0
- package/build/legacy/suspense.cjs.map +1 -1
- package/build/legacy/suspense.d.cts +27 -0
- package/build/legacy/suspense.d.cts.map +1 -1
- package/build/legacy/suspense.d.ts +27 -0
- package/build/legacy/suspense.d.ts.map +1 -1
- package/build/legacy/suspense.js +27 -0
- package/build/legacy/suspense.js.map +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +2 -22
- package/build/legacy/types.d.cts.map +1 -1
- package/build/legacy/types.d.ts +2 -22
- package/build/legacy/types.d.ts.map +1 -1
- package/build/legacy/types.js.map +1 -1
- package/build/legacy/useBaseQuery.cjs +13 -0
- package/build/legacy/useBaseQuery.cjs.map +1 -1
- package/build/legacy/useBaseQuery.d.cts +13 -0
- package/build/legacy/useBaseQuery.d.cts.map +1 -1
- package/build/legacy/useBaseQuery.d.ts +13 -0
- package/build/legacy/useBaseQuery.d.ts.map +1 -1
- package/build/legacy/useBaseQuery.js +13 -0
- package/build/legacy/useBaseQuery.js.map +1 -1
- package/build/legacy/useInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useInfiniteQuery.d.cts +12 -21
- package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useInfiniteQuery.d.ts +12 -21
- package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useInfiniteQuery.js.map +1 -1
- package/build/legacy/useIsFetching.cjs +0 -3
- package/build/legacy/useIsFetching.cjs.map +1 -1
- package/build/legacy/useIsFetching.d.cts +0 -3
- package/build/legacy/useIsFetching.d.cts.map +1 -1
- package/build/legacy/useIsFetching.d.ts +0 -3
- package/build/legacy/useIsFetching.d.ts.map +1 -1
- package/build/legacy/useIsFetching.js +0 -3
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.cjs +4 -8
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.d.cts +4 -8
- package/build/legacy/useMutation.d.cts.map +1 -1
- package/build/legacy/useMutation.d.ts +4 -8
- package/build/legacy/useMutation.d.ts.map +1 -1
- package/build/legacy/useMutation.js +4 -8
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/useMutationState.cjs +7 -6
- package/build/legacy/useMutationState.cjs.map +1 -1
- package/build/legacy/useMutationState.d.cts +0 -6
- package/build/legacy/useMutationState.d.cts.map +1 -1
- package/build/legacy/useMutationState.d.ts +0 -6
- package/build/legacy/useMutationState.d.ts.map +1 -1
- package/build/legacy/useMutationState.js +7 -6
- package/build/legacy/useMutationState.js.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.cjs +0 -3
- package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.cts +0 -3
- package/build/legacy/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.ts +0 -3
- package/build/legacy/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.js +0 -3
- package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/legacy/usePrefetchQuery.cjs +0 -3
- package/build/legacy/usePrefetchQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchQuery.d.cts +0 -3
- package/build/legacy/usePrefetchQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchQuery.d.ts +0 -3
- package/build/legacy/usePrefetchQuery.d.ts.map +1 -1
- package/build/legacy/usePrefetchQuery.js +0 -3
- package/build/legacy/usePrefetchQuery.js.map +1 -1
- package/build/legacy/useQueries.cjs +3 -3
- package/build/legacy/useQueries.cjs.map +1 -1
- package/build/legacy/useQueries.d.cts +3 -6
- package/build/legacy/useQueries.d.cts.map +1 -1
- package/build/legacy/useQueries.d.ts +3 -6
- package/build/legacy/useQueries.d.ts.map +1 -1
- package/build/legacy/useQueries.js +3 -3
- package/build/legacy/useQueries.js.map +1 -1
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +8 -13
- package/build/legacy/useQuery.d.cts.map +1 -1
- package/build/legacy/useQuery.d.ts +8 -13
- package/build/legacy/useQuery.d.ts.map +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.cjs +6 -8
- package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.cts +6 -8
- package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.ts +6 -8
- package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.js +6 -8
- package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/legacy/useSuspenseQueries.cjs.map +1 -1
- package/build/legacy/useSuspenseQueries.d.cts +0 -9
- package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
- package/build/legacy/useSuspenseQueries.d.ts +0 -9
- package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
- package/build/legacy/useSuspenseQueries.js.map +1 -1
- package/build/legacy/useSuspenseQuery.cjs +4 -6
- package/build/legacy/useSuspenseQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseQuery.d.cts +4 -6
- package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseQuery.d.ts +4 -6
- package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseQuery.js +4 -6
- package/build/legacy/useSuspenseQuery.js.map +1 -1
- package/build/legacy/utils.cjs +21 -1
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +15 -0
- package/build/legacy/utils.d.cts.map +1 -1
- package/build/legacy/utils.d.ts +15 -0
- package/build/legacy/utils.d.ts.map +1 -1
- package/build/legacy/utils.js +21 -1
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/HydrationBoundary.cjs +2 -3
- package/build/modern/HydrationBoundary.cjs.map +1 -1
- package/build/modern/HydrationBoundary.d.cts +3 -4
- package/build/modern/HydrationBoundary.d.cts.map +1 -1
- package/build/modern/HydrationBoundary.d.ts +2 -3
- package/build/modern/HydrationBoundary.d.ts.map +1 -1
- package/build/modern/HydrationBoundary.js +2 -3
- package/build/modern/HydrationBoundary.js.map +1 -1
- package/build/modern/IsRestoringProvider.cjs +0 -1
- package/build/modern/IsRestoringProvider.cjs.map +1 -1
- package/build/modern/IsRestoringProvider.d.cts +0 -1
- package/build/modern/IsRestoringProvider.d.cts.map +1 -1
- package/build/modern/IsRestoringProvider.d.ts +0 -1
- package/build/modern/IsRestoringProvider.d.ts.map +1 -1
- package/build/modern/IsRestoringProvider.js +0 -1
- package/build/modern/IsRestoringProvider.js.map +1 -1
- package/build/modern/QueryClientProvider.cjs +3 -4
- package/build/modern/QueryClientProvider.cjs.map +1 -1
- package/build/modern/QueryClientProvider.d.cts +4 -5
- package/build/modern/QueryClientProvider.d.cts.map +1 -1
- package/build/modern/QueryClientProvider.d.ts +3 -4
- package/build/modern/QueryClientProvider.d.ts.map +1 -1
- package/build/modern/QueryClientProvider.js +3 -4
- package/build/modern/QueryClientProvider.js.map +1 -1
- package/build/modern/QueryErrorResetBoundary.cjs +6 -4
- package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.cts +5 -5
- package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.ts +5 -5
- package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.js +6 -4
- package/build/modern/QueryErrorResetBoundary.js.map +1 -1
- package/build/modern/errorBoundaryUtils.cjs +21 -0
- package/build/modern/errorBoundaryUtils.cjs.map +1 -1
- package/build/modern/errorBoundaryUtils.d.cts +21 -0
- package/build/modern/errorBoundaryUtils.d.cts.map +1 -1
- package/build/modern/errorBoundaryUtils.d.ts +21 -0
- package/build/modern/errorBoundaryUtils.d.ts.map +1 -1
- package/build/modern/errorBoundaryUtils.js +21 -0
- package/build/modern/errorBoundaryUtils.js.map +1 -1
- package/build/modern/infiniteQueryOptions.cjs.map +1 -1
- package/build/modern/infiniteQueryOptions.d.cts +5 -16
- package/build/modern/infiniteQueryOptions.d.cts.map +1 -1
- package/build/modern/infiniteQueryOptions.d.ts +5 -16
- package/build/modern/infiniteQueryOptions.d.ts.map +1 -1
- package/build/modern/infiniteQueryOptions.js.map +1 -1
- package/build/modern/mutationOptions.cjs.map +1 -1
- package/build/modern/mutationOptions.d.cts +2 -6
- package/build/modern/mutationOptions.d.cts.map +1 -1
- package/build/modern/mutationOptions.d.ts +2 -6
- package/build/modern/mutationOptions.d.ts.map +1 -1
- package/build/modern/mutationOptions.js.map +1 -1
- package/build/modern/queryOptions.cjs.map +1 -1
- package/build/modern/queryOptions.d.cts +6 -16
- package/build/modern/queryOptions.d.cts.map +1 -1
- package/build/modern/queryOptions.d.ts +6 -16
- package/build/modern/queryOptions.d.ts.map +1 -1
- package/build/modern/queryOptions.js.map +1 -1
- package/build/modern/suspense.cjs +27 -0
- package/build/modern/suspense.cjs.map +1 -1
- package/build/modern/suspense.d.cts +27 -0
- package/build/modern/suspense.d.cts.map +1 -1
- package/build/modern/suspense.d.ts +27 -0
- package/build/modern/suspense.d.ts.map +1 -1
- package/build/modern/suspense.js +27 -0
- package/build/modern/suspense.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +2 -22
- package/build/modern/types.d.cts.map +1 -1
- package/build/modern/types.d.ts +2 -22
- package/build/modern/types.d.ts.map +1 -1
- package/build/modern/types.js.map +1 -1
- package/build/modern/useBaseQuery.cjs +13 -0
- package/build/modern/useBaseQuery.cjs.map +1 -1
- package/build/modern/useBaseQuery.d.cts +13 -0
- package/build/modern/useBaseQuery.d.cts.map +1 -1
- package/build/modern/useBaseQuery.d.ts +13 -0
- package/build/modern/useBaseQuery.d.ts.map +1 -1
- package/build/modern/useBaseQuery.js +13 -0
- package/build/modern/useBaseQuery.js.map +1 -1
- package/build/modern/useInfiniteQuery.cjs.map +1 -1
- package/build/modern/useInfiniteQuery.d.cts +12 -21
- package/build/modern/useInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useInfiniteQuery.d.ts +12 -21
- package/build/modern/useInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useInfiniteQuery.js.map +1 -1
- package/build/modern/useIsFetching.cjs +0 -3
- package/build/modern/useIsFetching.cjs.map +1 -1
- package/build/modern/useIsFetching.d.cts +0 -3
- package/build/modern/useIsFetching.d.cts.map +1 -1
- package/build/modern/useIsFetching.d.ts +0 -3
- package/build/modern/useIsFetching.d.ts.map +1 -1
- package/build/modern/useIsFetching.js +0 -3
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.cjs +4 -8
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.d.cts +4 -8
- package/build/modern/useMutation.d.cts.map +1 -1
- package/build/modern/useMutation.d.ts +4 -8
- package/build/modern/useMutation.d.ts.map +1 -1
- package/build/modern/useMutation.js +4 -8
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/useMutationState.cjs +7 -6
- package/build/modern/useMutationState.cjs.map +1 -1
- package/build/modern/useMutationState.d.cts +0 -6
- package/build/modern/useMutationState.d.cts.map +1 -1
- package/build/modern/useMutationState.d.ts +0 -6
- package/build/modern/useMutationState.d.ts.map +1 -1
- package/build/modern/useMutationState.js +7 -6
- package/build/modern/useMutationState.js.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.cjs +0 -3
- package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.cts +0 -3
- package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.ts +0 -3
- package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.js +0 -3
- package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/modern/usePrefetchQuery.cjs +0 -3
- package/build/modern/usePrefetchQuery.cjs.map +1 -1
- package/build/modern/usePrefetchQuery.d.cts +0 -3
- package/build/modern/usePrefetchQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchQuery.d.ts +0 -3
- package/build/modern/usePrefetchQuery.d.ts.map +1 -1
- package/build/modern/usePrefetchQuery.js +0 -3
- package/build/modern/usePrefetchQuery.js.map +1 -1
- package/build/modern/useQueries.cjs +3 -3
- package/build/modern/useQueries.cjs.map +1 -1
- package/build/modern/useQueries.d.cts +3 -6
- package/build/modern/useQueries.d.cts.map +1 -1
- package/build/modern/useQueries.d.ts +3 -6
- package/build/modern/useQueries.d.ts.map +1 -1
- package/build/modern/useQueries.js +3 -3
- package/build/modern/useQueries.js.map +1 -1
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +8 -13
- package/build/modern/useQuery.d.cts.map +1 -1
- package/build/modern/useQuery.d.ts +8 -13
- package/build/modern/useQuery.d.ts.map +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.cjs +6 -8
- package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.cts +6 -8
- package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.ts +6 -8
- package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.js +6 -8
- package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/modern/useSuspenseQueries.cjs.map +1 -1
- package/build/modern/useSuspenseQueries.d.cts +0 -9
- package/build/modern/useSuspenseQueries.d.cts.map +1 -1
- package/build/modern/useSuspenseQueries.d.ts +0 -9
- package/build/modern/useSuspenseQueries.d.ts.map +1 -1
- package/build/modern/useSuspenseQueries.js.map +1 -1
- package/build/modern/useSuspenseQuery.cjs +4 -6
- package/build/modern/useSuspenseQuery.cjs.map +1 -1
- package/build/modern/useSuspenseQuery.d.cts +4 -6
- package/build/modern/useSuspenseQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseQuery.d.ts +4 -6
- package/build/modern/useSuspenseQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseQuery.js +4 -6
- package/build/modern/useSuspenseQuery.js.map +1 -1
- package/build/modern/utils.cjs +21 -1
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +15 -0
- package/build/modern/utils.d.cts.map +1 -1
- package/build/modern/utils.d.ts +15 -0
- package/build/modern/utils.d.ts.map +1 -1
- package/build/modern/utils.js +21 -1
- package/build/modern/utils.js.map +1 -1
- package/package.json +8 -10
- package/src/HydrationBoundary.tsx +8 -8
- package/src/IsRestoringProvider.ts +0 -1
- package/src/QueryClientProvider.tsx +5 -6
- package/src/QueryErrorResetBoundary.tsx +11 -6
- package/src/errorBoundaryUtils.ts +22 -1
- package/src/infiniteQueryOptions.ts +5 -16
- package/src/mutationOptions.ts +2 -6
- package/src/queryOptions.ts +8 -17
- package/src/suspense.ts +29 -1
- package/src/types.ts +2 -22
- package/src/useBaseQuery.ts +20 -7
- package/src/useInfiniteQuery.ts +13 -22
- package/src/useIsFetching.ts +1 -4
- package/src/useMutation.ts +6 -10
- package/src/useMutationState.ts +11 -10
- package/src/usePrefetchInfiniteQuery.tsx +0 -3
- package/src/usePrefetchQuery.tsx +0 -3
- package/src/useQueries.ts +15 -18
- package/src/useQuery.ts +9 -14
- package/src/useSuspenseInfiniteQuery.ts +8 -10
- package/src/useSuspenseQueries.ts +2 -11
- package/src/useSuspenseQuery.ts +6 -8
- package/src/utils.ts +21 -1
package/build/modern/utils.cjs
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let preact_hooks = require("preact/hooks");
|
|
3
3
|
//#region src/utils.ts
|
|
4
|
+
/**
|
|
5
|
+
* Subscribes to an external store and returns its current snapshot, re-rendering when it changes.
|
|
6
|
+
* @param subscribe - Subscribes to the store, and returns a function that unsubscribes.
|
|
7
|
+
* @param getSnapshot - Returns the current snapshot of the store.
|
|
8
|
+
* @returns The current snapshot.
|
|
9
|
+
*/
|
|
4
10
|
function useSyncExternalStore(subscribe, getSnapshot) {
|
|
5
11
|
const value = getSnapshot();
|
|
6
12
|
const [{ _instance }, forceUpdate] = (0, preact_hooks.useState)({ _instance: {
|
|
@@ -24,6 +30,11 @@ function useSyncExternalStore(subscribe, getSnapshot) {
|
|
|
24
30
|
}, [subscribe]);
|
|
25
31
|
return value;
|
|
26
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Checks whether the store's snapshot changed since it was last read.
|
|
35
|
+
* @param inst - The stored snapshot and the function that reads the current one.
|
|
36
|
+
* @returns `true` if the current snapshot differs, or if reading it throws.
|
|
37
|
+
*/
|
|
27
38
|
function didSnapshotChange(inst) {
|
|
28
39
|
const latestGetSnapshot = inst._getSnapshot;
|
|
29
40
|
const prevValue = inst._value;
|
|
@@ -34,8 +45,17 @@ function didSnapshotChange(inst) {
|
|
|
34
45
|
return true;
|
|
35
46
|
}
|
|
36
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Like {@link useSyncExternalStore}, but returns a selected part of the snapshot, only updating it
|
|
50
|
+
* when `isEqual` reports a change.
|
|
51
|
+
* @param subscribe - Subscribes to the store, and returns a function that unsubscribes.
|
|
52
|
+
* @param getSnapshot - Returns the current snapshot of the store.
|
|
53
|
+
* @param selector - Selects the part of the snapshot to return.
|
|
54
|
+
* @param isEqual - Compares the previous and the new selection.
|
|
55
|
+
* @returns The selected part of the current snapshot.
|
|
56
|
+
*/
|
|
37
57
|
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, selector, isEqual) {
|
|
38
|
-
const selectedSnapshotRef = (0, preact_hooks.useRef)();
|
|
58
|
+
const selectedSnapshotRef = (0, preact_hooks.useRef)(void 0);
|
|
39
59
|
const getSelectedSnapshot = () => {
|
|
40
60
|
const selected = selector(getSnapshot());
|
|
41
61
|
if (selectedSnapshotRef.current === void 0 || !isEqual(selectedSnapshotRef.current, selected)) selectedSnapshotRef.current = selected;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":["useState","useRef"],"sources":["../../src/utils.ts"],"sourcesContent":["import { useEffect, useLayoutEffect, useRef, useState } from 'preact/hooks'\n\n/**\n * This is taken from https://github.com/preactjs/preact/blob/main/compat/src/hooks.js#L8-L54\n * which is taken from https://github.com/facebook/react/blob/main/packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js#L84\n * on a high level this cuts out the warnings, ... and attempts a smaller implementation.\n * This way we don't have to import preact/compat with side effects\n */\ntype InternalStore = {\n _value: any\n _getSnapshot: () => any\n}\ntype StoreRef = {\n _instance: InternalStore\n}\nexport function useSyncExternalStore(\n subscribe: (onStoreChange: () => void) => () => void,\n getSnapshot: () => any,\n) {\n const value = getSnapshot()\n\n const [{ _instance }, forceUpdate] = useState<StoreRef>({\n _instance: { _value: value, _getSnapshot: getSnapshot },\n })\n\n useLayoutEffect(() => {\n _instance._value = value\n _instance._getSnapshot = getSnapshot\n\n if (didSnapshotChange(_instance)) {\n forceUpdate({ _instance })\n }\n }, [subscribe, value, getSnapshot])\n\n useEffect(() => {\n if (didSnapshotChange(_instance)) {\n forceUpdate({ _instance })\n }\n\n return subscribe(() => {\n if (didSnapshotChange(_instance)) {\n forceUpdate({ _instance })\n }\n })\n }, [subscribe])\n\n return value\n}\n\nfunction didSnapshotChange(inst: {\n _getSnapshot: () => any\n _value: any\n}): boolean {\n const latestGetSnapshot = inst._getSnapshot\n const prevValue = inst._value\n try {\n const nextValue = latestGetSnapshot()\n return !Object.is(prevValue, nextValue)\n } catch (_error) {\n return true\n }\n}\n\nexport function useSyncExternalStoreWithSelector<TSnapshot, TSelected>(\n subscribe: (onStoreChange: () => void) => () => void,\n getSnapshot: () => TSnapshot,\n selector: (snapshot: TSnapshot) => TSelected,\n isEqual: (a: TSelected, b: TSelected) => boolean,\n): TSelected {\n const selectedSnapshotRef = useRef<TSelected | undefined>()\n\n const getSelectedSnapshot = () => {\n const snapshot = getSnapshot()\n const selected = selector(snapshot)\n\n if (\n selectedSnapshotRef.current === undefined ||\n !isEqual(selectedSnapshotRef.current, selected)\n ) {\n selectedSnapshotRef.current = selected\n }\n\n return selectedSnapshotRef.current\n }\n\n return useSyncExternalStore(subscribe, getSelectedSnapshot)\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":["useState","useRef"],"sources":["../../src/utils.ts"],"sourcesContent":["import { useEffect, useLayoutEffect, useRef, useState } from 'preact/hooks'\n\n/**\n * This is taken from https://github.com/preactjs/preact/blob/main/compat/src/hooks.js#L8-L54\n * which is taken from https://github.com/facebook/react/blob/main/packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js#L84\n * on a high level this cuts out the warnings, ... and attempts a smaller implementation.\n * This way we don't have to import preact/compat with side effects\n */\ntype InternalStore = {\n _value: any\n _getSnapshot: () => any\n}\ntype StoreRef = {\n _instance: InternalStore\n}\n/**\n * Subscribes to an external store and returns its current snapshot, re-rendering when it changes.\n * @param subscribe - Subscribes to the store, and returns a function that unsubscribes.\n * @param getSnapshot - Returns the current snapshot of the store.\n * @returns The current snapshot.\n */\nexport function useSyncExternalStore(\n subscribe: (onStoreChange: () => void) => () => void,\n getSnapshot: () => any,\n) {\n const value = getSnapshot()\n\n const [{ _instance }, forceUpdate] = useState<StoreRef>({\n _instance: { _value: value, _getSnapshot: getSnapshot },\n })\n\n useLayoutEffect(() => {\n _instance._value = value\n _instance._getSnapshot = getSnapshot\n\n if (didSnapshotChange(_instance)) {\n forceUpdate({ _instance })\n }\n }, [subscribe, value, getSnapshot])\n\n useEffect(() => {\n if (didSnapshotChange(_instance)) {\n forceUpdate({ _instance })\n }\n\n return subscribe(() => {\n if (didSnapshotChange(_instance)) {\n forceUpdate({ _instance })\n }\n })\n }, [subscribe])\n\n return value\n}\n\n/**\n * Checks whether the store's snapshot changed since it was last read.\n * @param inst - The stored snapshot and the function that reads the current one.\n * @returns `true` if the current snapshot differs, or if reading it throws.\n */\nfunction didSnapshotChange(inst: {\n _getSnapshot: () => any\n _value: any\n}): boolean {\n const latestGetSnapshot = inst._getSnapshot\n const prevValue = inst._value\n try {\n const nextValue = latestGetSnapshot()\n return !Object.is(prevValue, nextValue)\n } catch (_error) {\n return true\n }\n}\n\n/**\n * Like {@link useSyncExternalStore}, but returns a selected part of the snapshot, only updating it\n * when `isEqual` reports a change.\n * @param subscribe - Subscribes to the store, and returns a function that unsubscribes.\n * @param getSnapshot - Returns the current snapshot of the store.\n * @param selector - Selects the part of the snapshot to return.\n * @param isEqual - Compares the previous and the new selection.\n * @returns The selected part of the current snapshot.\n */\nexport function useSyncExternalStoreWithSelector<TSnapshot, TSelected>(\n subscribe: (onStoreChange: () => void) => () => void,\n getSnapshot: () => TSnapshot,\n selector: (snapshot: TSnapshot) => TSelected,\n isEqual: (a: TSelected, b: TSelected) => boolean,\n): TSelected {\n const selectedSnapshotRef = useRef<TSelected | undefined>(undefined)\n\n const getSelectedSnapshot = () => {\n const snapshot = getSnapshot()\n const selected = selector(snapshot)\n\n if (\n selectedSnapshotRef.current === undefined ||\n !isEqual(selectedSnapshotRef.current, selected)\n ) {\n selectedSnapshotRef.current = selected\n }\n\n return selectedSnapshotRef.current\n }\n\n return useSyncExternalStore(subscribe, getSelectedSnapshot)\n}\n"],"mappings":";;;;;;;;;AAqBA,SAAgB,qBACd,WACA,aACA;CACA,MAAM,QAAQ,YAAY;CAE1B,MAAM,CAAC,EAAE,aAAa,gBAAA,GAAeA,aAAAA,SAAAA,CAAmB,EACtD,WAAW;EAAE,QAAQ;EAAO,cAAc;CAAY,EACxD,CAAC;CAED,CAAA,GAAA,aAAA,gBAAA,OAAsB;EACpB,UAAU,SAAS;EACnB,UAAU,eAAe;EAEzB,IAAI,kBAAkB,SAAS,GAC7B,YAAY,EAAE,UAAU,CAAC;CAE7B,GAAG;EAAC;EAAW;EAAO;CAAW,CAAC;CAElC,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,IAAI,kBAAkB,SAAS,GAC7B,YAAY,EAAE,UAAU,CAAC;EAG3B,OAAO,gBAAgB;GACrB,IAAI,kBAAkB,SAAS,GAC7B,YAAY,EAAE,UAAU,CAAC;EAE7B,CAAC;CACH,GAAG,CAAC,SAAS,CAAC;CAEd,OAAO;AACT;;;;;;AAOA,SAAS,kBAAkB,MAGf;CACV,MAAM,oBAAoB,KAAK;CAC/B,MAAM,YAAY,KAAK;CACvB,IAAI;EACF,MAAM,YAAY,kBAAkB;EACpC,OAAO,CAAC,OAAO,GAAG,WAAW,SAAS;CACxC,SAAS,QAAQ;EACf,OAAO;CACT;AACF;;;;;;;;;;AAWA,SAAgB,iCACd,WACA,aACA,UACA,SACW;CACX,MAAM,uBAAA,GAAsBC,aAAAA,OAAAA,CAA8B,KAAA,CAAS;CAEnE,MAAM,4BAA4B;EAEhC,MAAM,WAAW,SADA,YACgB,CAAC;EAElC,IACE,oBAAoB,YAAY,KAAA,KAChC,CAAC,QAAQ,oBAAoB,SAAS,QAAQ,GAE9C,oBAAoB,UAAU;EAGhC,OAAO,oBAAoB;CAC7B;CAEA,OAAO,qBAAqB,WAAW,mBAAmB;AAC5D"}
|
package/build/modern/utils.d.cts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
//#region src/utils.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Subscribes to an external store and returns its current snapshot, re-rendering when it changes.
|
|
4
|
+
* @param subscribe - Subscribes to the store, and returns a function that unsubscribes.
|
|
5
|
+
* @param getSnapshot - Returns the current snapshot of the store.
|
|
6
|
+
* @returns The current snapshot.
|
|
7
|
+
*/
|
|
2
8
|
export declare function useSyncExternalStore(subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => any): any;
|
|
9
|
+
/**
|
|
10
|
+
* Like {@link useSyncExternalStore}, but returns a selected part of the snapshot, only updating it
|
|
11
|
+
* when `isEqual` reports a change.
|
|
12
|
+
* @param subscribe - Subscribes to the store, and returns a function that unsubscribes.
|
|
13
|
+
* @param getSnapshot - Returns the current snapshot of the store.
|
|
14
|
+
* @param selector - Selects the part of the snapshot to return.
|
|
15
|
+
* @param isEqual - Compares the previous and the new selection.
|
|
16
|
+
* @returns The selected part of the current snapshot.
|
|
17
|
+
*/
|
|
3
18
|
export declare function useSyncExternalStoreWithSelector<TSnapshot, TSelected>(subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => TSnapshot, selector: (snapshot: TSnapshot) => TSelected, isEqual: (a: TSelected, b: TSelected) => boolean): TSelected;
|
|
4
19
|
//#endregion
|
|
5
20
|
//# sourceMappingURL=utils.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","names":[],"sources":["../../src/utils.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.cts","names":[],"sources":["../../src/utils.ts"],"mappings":";;;;;;;wBAqBgB,qBACd,YAAY,0CACZ;;;;;;;;;;wBA4Dc,iCAAiC,WAAW,WAC1D,YAAY,0CACZ,mBAAmB,WACnB,WAAW,UAAU,cAAc,WACnC,UAAU,GAAG,WAAW,GAAG,wBAC1B"}
|
package/build/modern/utils.d.ts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
//#region src/utils.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Subscribes to an external store and returns its current snapshot, re-rendering when it changes.
|
|
4
|
+
* @param subscribe - Subscribes to the store, and returns a function that unsubscribes.
|
|
5
|
+
* @param getSnapshot - Returns the current snapshot of the store.
|
|
6
|
+
* @returns The current snapshot.
|
|
7
|
+
*/
|
|
2
8
|
export declare function useSyncExternalStore(subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => any): any;
|
|
9
|
+
/**
|
|
10
|
+
* Like {@link useSyncExternalStore}, but returns a selected part of the snapshot, only updating it
|
|
11
|
+
* when `isEqual` reports a change.
|
|
12
|
+
* @param subscribe - Subscribes to the store, and returns a function that unsubscribes.
|
|
13
|
+
* @param getSnapshot - Returns the current snapshot of the store.
|
|
14
|
+
* @param selector - Selects the part of the snapshot to return.
|
|
15
|
+
* @param isEqual - Compares the previous and the new selection.
|
|
16
|
+
* @returns The selected part of the current snapshot.
|
|
17
|
+
*/
|
|
3
18
|
export declare function useSyncExternalStoreWithSelector<TSnapshot, TSelected>(subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => TSnapshot, selector: (snapshot: TSnapshot) => TSelected, isEqual: (a: TSelected, b: TSelected) => boolean): TSelected;
|
|
4
19
|
//#endregion
|
|
5
20
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/utils.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/utils.ts"],"mappings":";;;;;;;wBAqBgB,qBACd,YAAY,0CACZ;;;;;;;;;;wBA4Dc,iCAAiC,WAAW,WAC1D,YAAY,0CACZ,mBAAmB,WACnB,WAAW,UAAU,cAAc,WACnC,UAAU,GAAG,WAAW,GAAG,wBAC1B"}
|
package/build/modern/utils.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
|
|
2
2
|
//#region src/utils.ts
|
|
3
|
+
/**
|
|
4
|
+
* Subscribes to an external store and returns its current snapshot, re-rendering when it changes.
|
|
5
|
+
* @param subscribe - Subscribes to the store, and returns a function that unsubscribes.
|
|
6
|
+
* @param getSnapshot - Returns the current snapshot of the store.
|
|
7
|
+
* @returns The current snapshot.
|
|
8
|
+
*/
|
|
3
9
|
function useSyncExternalStore(subscribe, getSnapshot) {
|
|
4
10
|
const value = getSnapshot();
|
|
5
11
|
const [{ _instance }, forceUpdate] = useState({ _instance: {
|
|
@@ -23,6 +29,11 @@ function useSyncExternalStore(subscribe, getSnapshot) {
|
|
|
23
29
|
}, [subscribe]);
|
|
24
30
|
return value;
|
|
25
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Checks whether the store's snapshot changed since it was last read.
|
|
34
|
+
* @param inst - The stored snapshot and the function that reads the current one.
|
|
35
|
+
* @returns `true` if the current snapshot differs, or if reading it throws.
|
|
36
|
+
*/
|
|
26
37
|
function didSnapshotChange(inst) {
|
|
27
38
|
const latestGetSnapshot = inst._getSnapshot;
|
|
28
39
|
const prevValue = inst._value;
|
|
@@ -33,8 +44,17 @@ function didSnapshotChange(inst) {
|
|
|
33
44
|
return true;
|
|
34
45
|
}
|
|
35
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Like {@link useSyncExternalStore}, but returns a selected part of the snapshot, only updating it
|
|
49
|
+
* when `isEqual` reports a change.
|
|
50
|
+
* @param subscribe - Subscribes to the store, and returns a function that unsubscribes.
|
|
51
|
+
* @param getSnapshot - Returns the current snapshot of the store.
|
|
52
|
+
* @param selector - Selects the part of the snapshot to return.
|
|
53
|
+
* @param isEqual - Compares the previous and the new selection.
|
|
54
|
+
* @returns The selected part of the current snapshot.
|
|
55
|
+
*/
|
|
36
56
|
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, selector, isEqual) {
|
|
37
|
-
const selectedSnapshotRef = useRef();
|
|
57
|
+
const selectedSnapshotRef = useRef(void 0);
|
|
38
58
|
const getSelectedSnapshot = () => {
|
|
39
59
|
const selected = selector(getSnapshot());
|
|
40
60
|
if (selectedSnapshotRef.current === void 0 || !isEqual(selectedSnapshotRef.current, selected)) selectedSnapshotRef.current = selected;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["import { useEffect, useLayoutEffect, useRef, useState } from 'preact/hooks'\n\n/**\n * This is taken from https://github.com/preactjs/preact/blob/main/compat/src/hooks.js#L8-L54\n * which is taken from https://github.com/facebook/react/blob/main/packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js#L84\n * on a high level this cuts out the warnings, ... and attempts a smaller implementation.\n * This way we don't have to import preact/compat with side effects\n */\ntype InternalStore = {\n _value: any\n _getSnapshot: () => any\n}\ntype StoreRef = {\n _instance: InternalStore\n}\nexport function useSyncExternalStore(\n subscribe: (onStoreChange: () => void) => () => void,\n getSnapshot: () => any,\n) {\n const value = getSnapshot()\n\n const [{ _instance }, forceUpdate] = useState<StoreRef>({\n _instance: { _value: value, _getSnapshot: getSnapshot },\n })\n\n useLayoutEffect(() => {\n _instance._value = value\n _instance._getSnapshot = getSnapshot\n\n if (didSnapshotChange(_instance)) {\n forceUpdate({ _instance })\n }\n }, [subscribe, value, getSnapshot])\n\n useEffect(() => {\n if (didSnapshotChange(_instance)) {\n forceUpdate({ _instance })\n }\n\n return subscribe(() => {\n if (didSnapshotChange(_instance)) {\n forceUpdate({ _instance })\n }\n })\n }, [subscribe])\n\n return value\n}\n\nfunction didSnapshotChange(inst: {\n _getSnapshot: () => any\n _value: any\n}): boolean {\n const latestGetSnapshot = inst._getSnapshot\n const prevValue = inst._value\n try {\n const nextValue = latestGetSnapshot()\n return !Object.is(prevValue, nextValue)\n } catch (_error) {\n return true\n }\n}\n\nexport function useSyncExternalStoreWithSelector<TSnapshot, TSelected>(\n subscribe: (onStoreChange: () => void) => () => void,\n getSnapshot: () => TSnapshot,\n selector: (snapshot: TSnapshot) => TSelected,\n isEqual: (a: TSelected, b: TSelected) => boolean,\n): TSelected {\n const selectedSnapshotRef = useRef<TSelected | undefined>()\n\n const getSelectedSnapshot = () => {\n const snapshot = getSnapshot()\n const selected = selector(snapshot)\n\n if (\n selectedSnapshotRef.current === undefined ||\n !isEqual(selectedSnapshotRef.current, selected)\n ) {\n selectedSnapshotRef.current = selected\n }\n\n return selectedSnapshotRef.current\n }\n\n return useSyncExternalStore(subscribe, getSelectedSnapshot)\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["import { useEffect, useLayoutEffect, useRef, useState } from 'preact/hooks'\n\n/**\n * This is taken from https://github.com/preactjs/preact/blob/main/compat/src/hooks.js#L8-L54\n * which is taken from https://github.com/facebook/react/blob/main/packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js#L84\n * on a high level this cuts out the warnings, ... and attempts a smaller implementation.\n * This way we don't have to import preact/compat with side effects\n */\ntype InternalStore = {\n _value: any\n _getSnapshot: () => any\n}\ntype StoreRef = {\n _instance: InternalStore\n}\n/**\n * Subscribes to an external store and returns its current snapshot, re-rendering when it changes.\n * @param subscribe - Subscribes to the store, and returns a function that unsubscribes.\n * @param getSnapshot - Returns the current snapshot of the store.\n * @returns The current snapshot.\n */\nexport function useSyncExternalStore(\n subscribe: (onStoreChange: () => void) => () => void,\n getSnapshot: () => any,\n) {\n const value = getSnapshot()\n\n const [{ _instance }, forceUpdate] = useState<StoreRef>({\n _instance: { _value: value, _getSnapshot: getSnapshot },\n })\n\n useLayoutEffect(() => {\n _instance._value = value\n _instance._getSnapshot = getSnapshot\n\n if (didSnapshotChange(_instance)) {\n forceUpdate({ _instance })\n }\n }, [subscribe, value, getSnapshot])\n\n useEffect(() => {\n if (didSnapshotChange(_instance)) {\n forceUpdate({ _instance })\n }\n\n return subscribe(() => {\n if (didSnapshotChange(_instance)) {\n forceUpdate({ _instance })\n }\n })\n }, [subscribe])\n\n return value\n}\n\n/**\n * Checks whether the store's snapshot changed since it was last read.\n * @param inst - The stored snapshot and the function that reads the current one.\n * @returns `true` if the current snapshot differs, or if reading it throws.\n */\nfunction didSnapshotChange(inst: {\n _getSnapshot: () => any\n _value: any\n}): boolean {\n const latestGetSnapshot = inst._getSnapshot\n const prevValue = inst._value\n try {\n const nextValue = latestGetSnapshot()\n return !Object.is(prevValue, nextValue)\n } catch (_error) {\n return true\n }\n}\n\n/**\n * Like {@link useSyncExternalStore}, but returns a selected part of the snapshot, only updating it\n * when `isEqual` reports a change.\n * @param subscribe - Subscribes to the store, and returns a function that unsubscribes.\n * @param getSnapshot - Returns the current snapshot of the store.\n * @param selector - Selects the part of the snapshot to return.\n * @param isEqual - Compares the previous and the new selection.\n * @returns The selected part of the current snapshot.\n */\nexport function useSyncExternalStoreWithSelector<TSnapshot, TSelected>(\n subscribe: (onStoreChange: () => void) => () => void,\n getSnapshot: () => TSnapshot,\n selector: (snapshot: TSnapshot) => TSelected,\n isEqual: (a: TSelected, b: TSelected) => boolean,\n): TSelected {\n const selectedSnapshotRef = useRef<TSelected | undefined>(undefined)\n\n const getSelectedSnapshot = () => {\n const snapshot = getSnapshot()\n const selected = selector(snapshot)\n\n if (\n selectedSnapshotRef.current === undefined ||\n !isEqual(selectedSnapshotRef.current, selected)\n ) {\n selectedSnapshotRef.current = selected\n }\n\n return selectedSnapshotRef.current\n }\n\n return useSyncExternalStore(subscribe, getSelectedSnapshot)\n}\n"],"mappings":";;;;;;;;AAqBA,SAAgB,qBACd,WACA,aACA;CACA,MAAM,QAAQ,YAAY;CAE1B,MAAM,CAAC,EAAE,aAAa,eAAe,SAAmB,EACtD,WAAW;EAAE,QAAQ;EAAO,cAAc;CAAY,EACxD,CAAC;CAED,sBAAsB;EACpB,UAAU,SAAS;EACnB,UAAU,eAAe;EAEzB,IAAI,kBAAkB,SAAS,GAC7B,YAAY,EAAE,UAAU,CAAC;CAE7B,GAAG;EAAC;EAAW;EAAO;CAAW,CAAC;CAElC,gBAAgB;EACd,IAAI,kBAAkB,SAAS,GAC7B,YAAY,EAAE,UAAU,CAAC;EAG3B,OAAO,gBAAgB;GACrB,IAAI,kBAAkB,SAAS,GAC7B,YAAY,EAAE,UAAU,CAAC;EAE7B,CAAC;CACH,GAAG,CAAC,SAAS,CAAC;CAEd,OAAO;AACT;;;;;;AAOA,SAAS,kBAAkB,MAGf;CACV,MAAM,oBAAoB,KAAK;CAC/B,MAAM,YAAY,KAAK;CACvB,IAAI;EACF,MAAM,YAAY,kBAAkB;EACpC,OAAO,CAAC,OAAO,GAAG,WAAW,SAAS;CACxC,SAAS,QAAQ;EACf,OAAO;CACT;AACF;;;;;;;;;;AAWA,SAAgB,iCACd,WACA,aACA,UACA,SACW;CACX,MAAM,sBAAsB,OAA8B,KAAA,CAAS;CAEnE,MAAM,4BAA4B;EAEhC,MAAM,WAAW,SADA,YACgB,CAAC;EAElC,IACE,oBAAoB,YAAY,KAAA,KAChC,CAAC,QAAQ,oBAAoB,SAAS,QAAQ,GAE9C,oBAAoB,UAAU;EAGhC,OAAO,oBAAoB;CAC7B;CAEA,OAAO,qBAAqB,WAAW,mBAAmB;AAC5D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/preact-query",
|
|
3
|
-
"version": "5.104.
|
|
3
|
+
"version": "5.104.3",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in preact",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,33 +43,31 @@
|
|
|
43
43
|
"!build/codemods/**/__tests__"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@tanstack/query-core": "5.104.
|
|
46
|
+
"@tanstack/query-core": "5.104.3"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@preact/preset-vite": "^2.10.6",
|
|
50
|
-
"@tanstack/query-persist-client-core": "5.104.
|
|
50
|
+
"@tanstack/query-persist-client-core": "5.104.3",
|
|
51
51
|
"@tanstack/query-test-utils": "0.0.0",
|
|
52
52
|
"@testing-library/preact": "^3.2.4",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"preact": "^10.29.8",
|
|
56
|
-
"preact-render-to-string": "^6.6.4",
|
|
53
|
+
"preact": "^11.0.1",
|
|
54
|
+
"preact-render-to-string": "^6.8.0",
|
|
57
55
|
"typescript": "6.0.3"
|
|
58
56
|
},
|
|
59
57
|
"peerDependencies": {
|
|
60
|
-
"preact": "^10.0.0"
|
|
58
|
+
"preact": "^10.0.0 || ^11.0.0-0"
|
|
61
59
|
},
|
|
62
60
|
"scripts": {
|
|
63
61
|
"clean": "premove ./build ./coverage ./dist-ts ./.cache/test-types",
|
|
64
62
|
"compile": "tsc --project tsconfig.json",
|
|
65
|
-
"test:
|
|
63
|
+
"test:oxlint": "oxlint ./src",
|
|
66
64
|
"test:types": "npm-run-all --serial test:types:*",
|
|
67
|
-
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts56 --tsBuildInfoFile .cache/test-types/ts56.tsbuildinfo",
|
|
68
65
|
"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts57 --tsBuildInfoFile .cache/test-types/ts57.tsbuildinfo",
|
|
69
66
|
"test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts58 --tsBuildInfoFile .cache/test-types/ts58.tsbuildinfo",
|
|
70
67
|
"test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts59 --tsBuildInfoFile .cache/test-types/ts59.tsbuildinfo",
|
|
71
68
|
"test:types:tscurrent": "tsc --project tsconfig.json --outDir .cache/test-types/tscurrent --tsBuildInfoFile .cache/test-types/tscurrent.tsbuildinfo",
|
|
72
69
|
"test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts70 --tsBuildInfoFile .cache/test-types/ts70.tsbuildinfo",
|
|
70
|
+
"test:types:ts71": "node ../../node_modules/typescript71/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts71 --tsBuildInfoFile .cache/test-types/ts71.tsbuildinfo",
|
|
73
71
|
"test:lib": "vitest",
|
|
74
72
|
"test:lib:dev": "pnpm run test:lib --watch",
|
|
75
73
|
"test:build": "publint --strict && attw --pack",
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { hydrate } from '@tanstack/query-core'
|
|
2
|
+
import { Fragment } from 'preact'
|
|
3
|
+
import { useEffect, useMemo, useRef } from 'preact/hooks'
|
|
4
|
+
|
|
5
|
+
import { useQueryClient } from './QueryClientProvider'
|
|
6
|
+
import type { ComponentChildren } from 'preact'
|
|
2
7
|
import type {
|
|
3
8
|
DehydratedState,
|
|
4
9
|
HydrateOptions,
|
|
5
10
|
OmitKeyof,
|
|
6
11
|
QueryClient,
|
|
7
12
|
} from '@tanstack/query-core'
|
|
8
|
-
import { Fragment } from 'preact'
|
|
9
|
-
import type { ComponentChildren } from 'preact'
|
|
10
|
-
import { useEffect, useMemo, useRef } from 'preact/hooks'
|
|
11
|
-
|
|
12
|
-
import { useQueryClient } from './QueryClientProvider'
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* The props accepted by `HydrationBoundary`.
|
|
@@ -47,11 +47,11 @@ export interface HydrationBoundaryProps {
|
|
|
47
47
|
* update timestamp.
|
|
48
48
|
*
|
|
49
49
|
* Note: Only `queries` can be dehydrated with an `HydrationBoundary`.
|
|
50
|
-
*
|
|
50
|
+
* @param props - The dehydrated `state` to hydrate, the hydrate `options`, an optional custom
|
|
51
|
+
* `queryClient`, and the `children` to render.
|
|
51
52
|
* @returns The provided `children`, rendered unconditionally. New queries in `state` are hydrated into the
|
|
52
53
|
* cache during render; for queries already in the cache, only newer dehydrated data is hydrated, in an effect
|
|
53
54
|
* after commit.
|
|
54
|
-
*
|
|
55
55
|
* @example
|
|
56
56
|
* ```tsx
|
|
57
57
|
* import { HydrationBoundary } from '@tanstack/preact-query'
|
|
@@ -60,7 +60,6 @@ export interface HydrationBoundaryProps {
|
|
|
60
60
|
* return <HydrationBoundary state={dehydratedState}>...</HydrationBoundary>
|
|
61
61
|
* }
|
|
62
62
|
* ```
|
|
63
|
-
*
|
|
64
63
|
* @example
|
|
65
64
|
* Server-side prefetch handed off to the client via `dehydrate`:
|
|
66
65
|
* ```tsx
|
|
@@ -122,6 +121,7 @@ export const HydrationBoundary = ({
|
|
|
122
121
|
// State is supplied from the outside and we might as well fail
|
|
123
122
|
// gracefully if it has the wrong shape, so while we type `queries`
|
|
124
123
|
// as required, we still provide a fallback.
|
|
124
|
+
// oxlint-disable-next-line typescript/no-unnecessary-condition
|
|
125
125
|
const queries = state.queries || []
|
|
126
126
|
|
|
127
127
|
const newQueries: DehydratedState['queries'] = []
|
|
@@ -7,7 +7,6 @@ const IsRestoringContext = createContext(false)
|
|
|
7
7
|
* If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` hook alongside it to
|
|
8
8
|
* check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid
|
|
9
9
|
* race conditions between the restore and mounting queries.
|
|
10
|
-
*
|
|
11
10
|
* @returns `true` while a persisted client is being restored, `false` otherwise.
|
|
12
11
|
*/
|
|
13
12
|
export const useIsRestoring = () => useContext(IsRestoringContext)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { QueryClient } from '@tanstack/query-core'
|
|
2
1
|
import { createContext } from 'preact'
|
|
3
|
-
import type { ComponentChildren, VNode } from 'preact'
|
|
4
2
|
import { useContext, useEffect } from 'preact/hooks'
|
|
3
|
+
import type { QueryClient } from '@tanstack/query-core'
|
|
4
|
+
import type { ComponentChildren, VNode } from 'preact'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The context that `useQueryClient` reads from. `QueryClientProvider` is the normal way to set it.
|
|
@@ -12,11 +12,11 @@ export const QueryClientContext = createContext<QueryClient | undefined>(
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* The `useQueryClient` hook returns the current `QueryClient` instance.
|
|
15
|
-
*
|
|
16
15
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
17
16
|
* be used.
|
|
18
17
|
* @returns The current `QueryClient` instance.
|
|
19
|
-
* @throws If no `queryClient` argument is passed and no `QueryClientProvider` is found in the
|
|
18
|
+
* @throws {Error} If no `queryClient` argument is passed and no `QueryClientProvider` is found in the
|
|
19
|
+
* component tree.
|
|
20
20
|
*/
|
|
21
21
|
export const useQueryClient = (queryClient?: QueryClient) => {
|
|
22
22
|
const client = useContext(QueryClientContext)
|
|
@@ -53,9 +53,8 @@ export type QueryClientProviderProps = {
|
|
|
53
53
|
* calls `client.mount()`/`client.unmount()` as this component mounts/unmounts, which subscribes the client to
|
|
54
54
|
* focus/online events (resuming any paused mutations and refetching as needed when the app regains focus or
|
|
55
55
|
* comes back online).
|
|
56
|
-
*
|
|
56
|
+
* @param props - The `client` to provide, and the `children` that get access to it.
|
|
57
57
|
* @returns The provided `children`, wrapped so they can read the `QueryClient` via `useQueryClient`.
|
|
58
|
-
*
|
|
59
58
|
* @example
|
|
60
59
|
* ```tsx
|
|
61
60
|
* import { QueryClient, QueryClientProvider } from '@tanstack/preact-query'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext } from 'preact'
|
|
2
|
-
import type { ComponentChildren } from 'preact'
|
|
3
2
|
import { useContext, useState } from 'preact/hooks'
|
|
3
|
+
import type { ComponentChildren } from 'preact'
|
|
4
4
|
|
|
5
5
|
// CONTEXT
|
|
6
6
|
|
|
@@ -19,6 +19,10 @@ export type QueryErrorIsResetFunction = () => boolean
|
|
|
19
19
|
*/
|
|
20
20
|
export type QueryErrorClearResetFunction = () => void
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* The value a `QueryErrorResetBoundary` shares through context, used to reset query errors within
|
|
24
|
+
* it and to check whether a reset was requested.
|
|
25
|
+
*/
|
|
22
26
|
export interface QueryErrorResetBoundaryValue {
|
|
23
27
|
/**
|
|
24
28
|
* Clears the reset state, so queries know not to try again until the boundary is reset again.
|
|
@@ -34,6 +38,11 @@ export interface QueryErrorResetBoundaryValue {
|
|
|
34
38
|
reset: QueryErrorResetFunction
|
|
35
39
|
}
|
|
36
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Creates the value shared through the boundary's context, which tracks whether a reset was
|
|
43
|
+
* requested.
|
|
44
|
+
* @returns The `clearReset`, `isReset`, and `reset` functions of the boundary.
|
|
45
|
+
*/
|
|
37
46
|
function createValue(): QueryErrorResetBoundaryValue {
|
|
38
47
|
let isReset = false
|
|
39
48
|
return {
|
|
@@ -56,9 +65,7 @@ const QueryErrorResetBoundaryContext = createContext(createValue())
|
|
|
56
65
|
/**
|
|
57
66
|
* This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary
|
|
58
67
|
* defined it will reset them globally.
|
|
59
|
-
*
|
|
60
68
|
* @returns The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
61
|
-
*
|
|
62
69
|
* @example
|
|
63
70
|
* ```tsx
|
|
64
71
|
* import { useErrorBoundary } from 'preact/hooks'
|
|
@@ -89,7 +96,6 @@ export const useQueryErrorResetBoundary = () =>
|
|
|
89
96
|
|
|
90
97
|
/**
|
|
91
98
|
* A render-prop function usable as `children` on `QueryErrorResetBoundary`.
|
|
92
|
-
*
|
|
93
99
|
* @param value - The boundary's {@link QueryErrorResetBoundaryValue}.
|
|
94
100
|
* @returns The children to render.
|
|
95
101
|
*/
|
|
@@ -112,10 +118,9 @@ export interface QueryErrorResetBoundaryProps {
|
|
|
112
118
|
* When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to
|
|
113
119
|
* try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can
|
|
114
120
|
* reset any query errors within the boundaries of the component.
|
|
115
|
-
*
|
|
121
|
+
* @param props - The `children` to render.
|
|
116
122
|
* @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}
|
|
117
123
|
* if `children` is a function.
|
|
118
|
-
*
|
|
119
124
|
* @example
|
|
120
125
|
* ```tsx
|
|
121
126
|
* import { useErrorBoundary } from 'preact/hooks'
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { shouldThrowError } from '@tanstack/query-core'
|
|
2
|
+
import { useEffect } from 'preact/hooks'
|
|
2
3
|
import type {
|
|
3
4
|
DefaultedQueryObserverOptions,
|
|
4
5
|
Query,
|
|
@@ -6,10 +7,17 @@ import type {
|
|
|
6
7
|
QueryObserverResult,
|
|
7
8
|
ThrowOnError,
|
|
8
9
|
} from '@tanstack/query-core'
|
|
9
|
-
import { useEffect } from 'preact/hooks'
|
|
10
10
|
|
|
11
11
|
import type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Turns off `retryOnMount` for a query that throws its errors (with `suspense` or `throwOnError`),
|
|
15
|
+
* unless the error boundary has been reset, so a remount doesn't retry the failed query before the
|
|
16
|
+
* user resets the boundary. Mutates the options.
|
|
17
|
+
* @param options - The defaulted query options to adjust.
|
|
18
|
+
* @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
|
|
19
|
+
* @param query - The query, used to evaluate a `throwOnError` function against its error.
|
|
20
|
+
*/
|
|
13
21
|
export const ensurePreventErrorBoundaryRetry = <
|
|
14
22
|
TQueryFnData,
|
|
15
23
|
TError,
|
|
@@ -40,6 +48,11 @@ export const ensurePreventErrorBoundaryRetry = <
|
|
|
40
48
|
}
|
|
41
49
|
}
|
|
42
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Clears the reset state of the error boundary after the component mounts, so later errors are
|
|
53
|
+
* thrown to the boundary again.
|
|
54
|
+
* @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
|
|
55
|
+
*/
|
|
43
56
|
export const useClearResetErrorBoundary = (
|
|
44
57
|
errorResetBoundary: QueryErrorResetBoundaryValue,
|
|
45
58
|
) => {
|
|
@@ -48,6 +61,14 @@ export const useClearResetErrorBoundary = (
|
|
|
48
61
|
}, [errorResetBoundary])
|
|
49
62
|
}
|
|
50
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Checks whether the query error should be thrown to the nearest error boundary: the query errored
|
|
66
|
+
* and isn't fetching, the boundary hasn't been reset, and either `suspense` is enabled with no data
|
|
67
|
+
* or `throwOnError` says so.
|
|
68
|
+
* @param params - The observer `result`, the `errorResetBoundary`, the `throwOnError` option, the
|
|
69
|
+
* `query`, and the `suspense` option.
|
|
70
|
+
* @returns `true` if the error should be thrown.
|
|
71
|
+
*/
|
|
51
72
|
export const getHasError = <
|
|
52
73
|
TData,
|
|
53
74
|
TError,
|
|
@@ -14,7 +14,6 @@ import type { UseInfiniteQueryOptions } from './types'
|
|
|
14
14
|
/**
|
|
15
15
|
* The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`
|
|
16
16
|
* may be `undefined` while the query is `pending`.
|
|
17
|
-
*
|
|
18
17
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
19
18
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
20
19
|
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
@@ -54,7 +53,6 @@ export type UndefinedInitialDataInfiniteOptions<
|
|
|
54
53
|
* The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set and
|
|
55
54
|
* `queryFn` is not `skipToken` — same as {@link UndefinedInitialDataInfiniteOptions}, but `queryFn` may not be
|
|
56
55
|
* `skipToken`.
|
|
57
|
-
*
|
|
58
56
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
59
57
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
60
58
|
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
@@ -93,7 +91,6 @@ export type UnusedSkipTokenInfiniteOptions<
|
|
|
93
91
|
/**
|
|
94
92
|
* The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is
|
|
95
93
|
* never `undefined` (unless a `select` changes `TData` to include `undefined`).
|
|
96
|
-
*
|
|
97
94
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
98
95
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
99
96
|
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
@@ -133,13 +130,11 @@ export type DefinedInitialDataInfiniteOptions<
|
|
|
133
130
|
* `options.queryKey` is required and is the query key to generate options for.
|
|
134
131
|
*
|
|
135
132
|
* This overload is selected when `initialData` is set.
|
|
136
|
-
*
|
|
137
|
-
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
138
133
|
* @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.
|
|
139
134
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
140
135
|
* @remarks See {@link useInfiniteQuery} for examples that fetch further pages, from a button click or
|
|
141
136
|
* automatically as the user scrolls.
|
|
142
|
-
*
|
|
137
|
+
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
143
138
|
* @example
|
|
144
139
|
* ```tsx
|
|
145
140
|
* import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/preact-query'
|
|
@@ -195,11 +190,11 @@ export function infiniteQueryOptions<
|
|
|
195
190
|
* You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
|
|
196
191
|
* These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
|
|
197
192
|
* `options.queryKey` is required and is the query key to generate options for.
|
|
198
|
-
*
|
|
193
|
+
* @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
199
194
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
200
195
|
* @remarks See {@link useInfiniteQuery} for examples that fetch further pages, from a button click or
|
|
201
196
|
* automatically as the user scrolls.
|
|
202
|
-
*
|
|
197
|
+
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
203
198
|
* @example
|
|
204
199
|
* A parameterized factory, so the same options object can be reused per `postId`:
|
|
205
200
|
* ```tsx
|
|
@@ -226,9 +221,6 @@ export function infiniteQueryOptions<
|
|
|
226
221
|
* )
|
|
227
222
|
* }
|
|
228
223
|
* ```
|
|
229
|
-
*
|
|
230
|
-
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
231
|
-
* @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
232
224
|
*/
|
|
233
225
|
export function infiniteQueryOptions<
|
|
234
226
|
TQueryFnData,
|
|
@@ -257,11 +249,11 @@ export function infiniteQueryOptions<
|
|
|
257
249
|
* You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
|
|
258
250
|
* These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
|
|
259
251
|
* `options.queryKey` is required and is the query key to generate options for.
|
|
260
|
-
*
|
|
252
|
+
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
261
253
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
262
254
|
* @remarks See {@link useInfiniteQuery} for examples that fetch further pages (from a button click or
|
|
263
255
|
* automatically as the user scrolls) and that use `skipToken` to disable the query until `postId` is set.
|
|
264
|
-
*
|
|
256
|
+
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
265
257
|
* @example
|
|
266
258
|
* A parameterized factory, so the same options object can be reused per `postId`:
|
|
267
259
|
* ```tsx
|
|
@@ -288,9 +280,6 @@ export function infiniteQueryOptions<
|
|
|
288
280
|
* )
|
|
289
281
|
* }
|
|
290
282
|
* ```
|
|
291
|
-
*
|
|
292
|
-
* @see {@link useInfiniteQuery} to run an infinite query with these options.
|
|
293
|
-
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.
|
|
294
283
|
*/
|
|
295
284
|
export function infiniteQueryOptions<
|
|
296
285
|
TQueryFnData,
|
package/src/mutationOptions.ts
CHANGED
|
@@ -6,12 +6,10 @@ import type { UseMutationOptions } from './types'
|
|
|
6
6
|
* You can generally pass everything to `mutationOptions` that you can also pass to `useMutation`. A
|
|
7
7
|
* `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with
|
|
8
8
|
* `useMutationState`.
|
|
9
|
-
*
|
|
10
|
-
* @see {@link useMutation} to run the mutation these options describe.
|
|
11
9
|
* @param options - The mutation options to use, identical to what you'd pass to `useMutation`, with a
|
|
12
10
|
* required `mutationKey`.
|
|
13
11
|
* @returns The same options object, unchanged.
|
|
14
|
-
*
|
|
12
|
+
* @see {@link useMutation} to run the mutation these options describe.
|
|
15
13
|
* @example
|
|
16
14
|
* Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global "saving…" indicator:
|
|
17
15
|
* ```tsx
|
|
@@ -50,13 +48,11 @@ export function mutationOptions<
|
|
|
50
48
|
* `mutationKey` is required on this overload — use this when you don't need to target the mutation via a
|
|
51
49
|
* `mutationKey` filter later (e.g. with `useMutationState`); it can still be observed through other filters,
|
|
52
50
|
* such as `status`.
|
|
53
|
-
*
|
|
54
|
-
* @see {@link useMutation} to run the mutation these options describe.
|
|
55
51
|
* @param options - The mutation options to use, identical to what you'd pass to `useMutation`, without a
|
|
56
52
|
* `mutationKey`.
|
|
57
53
|
* @returns The same options object, unchanged.
|
|
58
54
|
* @remarks See the other overload's example for looking a mutation up via `useMutationState`.
|
|
59
|
-
*
|
|
55
|
+
* @see {@link useMutation} to run the mutation these options describe.
|
|
60
56
|
* @example
|
|
61
57
|
* ```tsx
|
|
62
58
|
* import { mutationOptions, useMutation } from '@tanstack/preact-query'
|
package/src/queryOptions.ts
CHANGED
|
@@ -14,7 +14,6 @@ import type { UseQueryOptions } from './types'
|
|
|
14
14
|
/**
|
|
15
15
|
* The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be
|
|
16
16
|
* `undefined` while the query is `pending`.
|
|
17
|
-
*
|
|
18
17
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
19
18
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
20
19
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
@@ -42,7 +41,6 @@ export type UndefinedInitialDataOptions<
|
|
|
42
41
|
/**
|
|
43
42
|
* The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is
|
|
44
43
|
* not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.
|
|
45
|
-
*
|
|
46
44
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
47
45
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
48
46
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
@@ -72,7 +70,6 @@ export type UnusedSkipTokenOptions<
|
|
|
72
70
|
/**
|
|
73
71
|
* The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
|
|
74
72
|
* `undefined` (unless a `select` changes `TData` to include `undefined`).
|
|
75
|
-
*
|
|
76
73
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
77
74
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
78
75
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
@@ -92,7 +89,8 @@ export type DefinedInitialDataOptions<
|
|
|
92
89
|
* cache.
|
|
93
90
|
*/
|
|
94
91
|
initialData:
|
|
95
|
-
|
|
92
|
+
| NonUndefinedGuard<TQueryFnData>
|
|
93
|
+
| (() => NonUndefinedGuard<TQueryFnData>)
|
|
96
94
|
/**
|
|
97
95
|
* Optional here, but omitting it is only safe when no fetch will be attempted — for example with
|
|
98
96
|
* `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no
|
|
@@ -108,12 +106,10 @@ export type DefinedInitialDataOptions<
|
|
|
108
106
|
*
|
|
109
107
|
* This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless
|
|
110
108
|
* a `select` changes `TData` to include `undefined`).
|
|
111
|
-
*
|
|
112
|
-
* @see {@link useQuery} to run a query with these options.
|
|
113
|
-
* @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
|
|
114
109
|
* @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` set.
|
|
115
110
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
116
|
-
*
|
|
111
|
+
* @see {@link useQuery} to run a query with these options.
|
|
112
|
+
* @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
|
|
117
113
|
* @example
|
|
118
114
|
* ```tsx
|
|
119
115
|
* import { queryOptions, useQuery } from '@tanstack/preact-query'
|
|
@@ -154,12 +150,10 @@ export function queryOptions<
|
|
|
154
150
|
* You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
|
|
155
151
|
* be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
|
|
156
152
|
* is the query key to generate options for.
|
|
157
|
-
*
|
|
158
|
-
* @see {@link useQuery} to run a query with these options.
|
|
159
|
-
* @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
|
|
160
153
|
* @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `useQuery`.
|
|
161
154
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
162
|
-
*
|
|
155
|
+
* @see {@link useQuery} to run a query with these options.
|
|
156
|
+
* @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
|
|
163
157
|
* @example
|
|
164
158
|
* A parameterized factory, so the same options object can be reused per `id`:
|
|
165
159
|
* ```tsx
|
|
@@ -195,13 +189,11 @@ export function queryOptions<
|
|
|
195
189
|
* You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can
|
|
196
190
|
* be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
|
|
197
191
|
* is the query key to generate options for.
|
|
198
|
-
*
|
|
199
|
-
* @see {@link useQuery} to run a query with these options.
|
|
200
|
-
* @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
|
|
201
192
|
* @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `useQuery`.
|
|
202
193
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
203
194
|
* @remarks This is the only overload that accepts `queryFn: skipToken`, shown below.
|
|
204
|
-
*
|
|
195
|
+
* @see {@link useQuery} to run a query with these options.
|
|
196
|
+
* @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
|
|
205
197
|
* @example
|
|
206
198
|
* A parameterized factory, so the same options object can be reused per `id`:
|
|
207
199
|
* ```tsx
|
|
@@ -222,7 +214,6 @@ export function queryOptions<
|
|
|
222
214
|
* return <h1>{data.title}</h1>
|
|
223
215
|
* }
|
|
224
216
|
* ```
|
|
225
|
-
*
|
|
226
217
|
* @example
|
|
227
218
|
* A factory that disables the query, type safe, until `postId` is set:
|
|
228
219
|
* ```tsx
|