Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24.0.0
node-version: 25.0.0
cache: 'npm'
cache-dependency-path: package-lock.json

Expand All @@ -39,7 +39,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24.0.0
node-version: 25.0.0
cache: 'npm'
cache-dependency-path: package-lock.json

Expand All @@ -59,7 +59,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24.0.0
node-version: 25.0.0
cache: 'npm'
cache-dependency-path: package-lock.json

Expand All @@ -81,7 +81,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24.0.0
node-version: 25.0.0
cache: 'npm'
cache-dependency-path: package-lock.json

Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24
25
28 changes: 26 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"prettier": "^3.6.2",
"react": "^19.1.1",
"react-dom": "^19.1.1",
"react-error-boundary": "^6.0.0",
"solid-js": "^1.9.9",
"typescript": "~5.9.3",
"typescript-eslint": "^8.46.2",
Expand Down
8 changes: 1 addition & 7 deletions src/react/components/QueryPrefetchTags.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { QueryInstance } from 'query/react:hooks/useQueryInstance'
import type { ReactNode, LinkHTMLAttributes } from 'react'
import { useMemo } from 'react'
import { useQueryPrefetch } from 'query/react:hooks/useQueryPrefetch'

type Additional = LinkHTMLAttributes<HTMLLinkElement> & QueryInstance
Expand All @@ -13,12 +12,7 @@ export interface QueryPrefetchTagsProps extends Additional {
export function QueryPrefetchTags({ keys, children, ...options }: QueryPrefetchTagsProps) {
useQueryPrefetch(keys, options)

const tags = useMemo(
function () {
return keys.map((key) => <link rel="preload" href={key} as="fetch" {...options} />)
},
[keys, options]
)
const tags = keys.map((key) => <link rel="preload" href={key} as="fetch" {...options} />)

return (
<>
Expand Down
18 changes: 4 additions & 14 deletions src/react/components/QueryProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useMemo, type ReactNode } from 'react'
import { useEffect, type ReactNode } from 'react'
import { Context, type ContextValue } from 'query/react:context'
import { createQuery, type Query } from 'query:index'
import { createQuery } from 'query:index'

export interface QueryProviderProps extends ContextValue {
children?: ReactNode
Expand All @@ -12,12 +12,7 @@ export function QueryProvider({
ignoreTransitionContext,
query,
}: QueryProviderProps) {
const localQuery = useMemo<Query>(
function () {
return query ?? createQuery()
},
[query]
)
const localQuery = query ?? createQuery()

useEffect(
function () {
Expand All @@ -35,12 +30,7 @@ export function QueryProvider({
[localQuery]
)

const value = useMemo(
function (): ContextValue {
return { query: localQuery, clearOnForget, ignoreTransitionContext }
},
[localQuery, clearOnForget, ignoreTransitionContext]
)
const value = { query: localQuery, clearOnForget, ignoreTransitionContext }

return <Context value={value}>{children}</Context>
}
11 changes: 3 additions & 8 deletions src/react/components/QueryTransition.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TransitionContext, type QueryTransitionContextValue } from 'query/react:transition'
import { useMemo, type ReactNode, type TransitionStartFunction } from 'react'
import { TransitionContext } from 'query/react:transition'
import { type ReactNode, type TransitionStartFunction } from 'react'

export interface QueryTransitionProps {
isPending: boolean
Expand All @@ -8,12 +8,7 @@ export interface QueryTransitionProps {
}

export function QueryTransition({ children, startTransition, isPending }: QueryTransitionProps) {
const value = useMemo(
function (): QueryTransitionContextValue {
return { startTransition, isPending }
},
[startTransition, isPending]
)
const value = { startTransition, isPending }

return <TransitionContext value={value}>{children}</TransitionContext>
}
10 changes: 1 addition & 9 deletions src/react/hooks/useQuery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useMemo, useDebugValue } from 'react'
import { type ContextValue } from 'query/react:context'
import { type Options } from 'query:index'
import { type QueryInstance } from './useQueryInstance'
Expand All @@ -16,16 +15,9 @@ export interface Resource<T = unknown> extends AdditionalHooks<T> {
export type ResourceOptions<T = unknown> = ContextValue & Options<T> & QueryInstance

export function useQuery<T = unknown>(key: string, options?: ResourceOptions<T>): Resource<T> {
useDebugValue('useQuery')

const basic = useQueryBasic<T>(key, options)
const actions = useQueryActions<T>(key, options)
const status = useQueryStatus(key, options)

return useMemo(
function (): Resource<T> {
return { ...basic, ...actions, ...status }
},
[basic, actions, status]
)
return { ...basic, ...actions, ...status }
}
59 changes: 21 additions & 38 deletions src/react/hooks/useQueryActions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { type MutateOptions, type MutationValue, type Options } from 'query:index'
import { useCallback, useDebugValue, useMemo } from 'react'
import { useQueryInstance, type QueryInstance } from './useQueryInstance'

export interface QueryActions<T = unknown> {
readonly refetch: (refetchOptions?: Options<T>) => Promise<T>
readonly mutate: (value: MutationValue<T>, options?: MutateOptions<T>) => Promise<T>
readonly forget: () => void
readonly forget: () => Promise<void>
}

export type QueryActionsOptions<T = unknown> = Options<T> & QueryInstance
Expand All @@ -14,8 +13,6 @@ export function useQueryActions<T = unknown>(
key: string,
options?: QueryActionsOptions<T>
): QueryActions<T> {
useDebugValue('useQueryActions')

const {
expiration: oExpiration,
fetcher: oFetcher,
Expand All @@ -26,38 +23,24 @@ export function useQueryActions<T = unknown>(

const { query, mutate, forget } = useQueryInstance(options)

const refetch = useCallback(
function (refetchOptions?: Options<T>) {
return query<T>(key, {
stale: oStale ?? false,
expiration: oExpiration,
fetcher: oFetcher,
removeOnError: oRemoveOnError,
fresh: oFresh,
...refetchOptions,
})
},
[query, key, oExpiration, oFetcher, oStale, oRemoveOnError, oFresh]
)

const localMutate = useCallback(
function <T = unknown>(value: MutationValue<T>, options?: MutateOptions<T>) {
return mutate(key, value, options)
},
[mutate, key]
)

const localForget = useCallback(
async function () {
await forget(key)
},
[forget, key]
)

return useMemo(
function () {
return { refetch, mutate: localMutate, forget: localForget }
},
[refetch, localMutate, localForget]
)
function refetch(refetchOptions?: Options<T>) {
return query<T>(key, {
stale: oStale ?? false,
expiration: oExpiration,
fetcher: oFetcher,
removeOnError: oRemoveOnError,
fresh: oFresh,
...refetchOptions,
})
}

function localMutate<T = unknown>(value: MutationValue<T>, options?: MutateOptions<T>) {
return mutate(key, value, options)
}

async function localForget() {
await forget(key)
}

return { refetch, mutate: localMutate, forget: localForget }
}
70 changes: 15 additions & 55 deletions src/react/hooks/useQueryBasic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, use, useState, useMemo, useDebugValue, useTransition } from 'react'
import { useEffect, use, useState, useTransition } from 'react'
import { type ContextValue } from 'query/react:context'
import { type Options } from 'query:index'
import { useQueryContext } from './useQueryContext'
Expand All @@ -16,8 +16,6 @@ export function useQueryBasic<T = unknown>(
key: string,
options?: BasicResourceOptions<T>
): BasicResource<T> {
useDebugValue('useQueryBasic')

const { clearOnForget: cClearOnForget, ignoreTransitionContext: cIgnoreTransitionContext } =
useQueryContext()

Expand All @@ -36,55 +34,22 @@ export function useQueryBasic<T = unknown>(

const [isLocalPending, startLocalTransition] = useTransition()
const { query, expiration, subscribe } = useQueryInstance(options)
const ignoreTransitionContext = oIgnoreTransitionContext ?? cIgnoreTransitionContext ?? false
const isPending = ignoreTransitionContext ? isLocalPending : (isContextPending ?? isLocalPending)

const ignoreTransitionContext = useMemo(
function () {
return oIgnoreTransitionContext ?? cIgnoreTransitionContext ?? false
},
[oIgnoreTransitionContext, cIgnoreTransitionContext]
)

const isPending = useMemo(
function () {
if (ignoreTransitionContext) {
return isLocalPending
}
const startTransition = ignoreTransitionContext
? startLocalTransition
: (startContextTransition ?? startLocalTransition)

return isContextPending ?? isLocalPending
},
[isContextPending, isLocalPending, ignoreTransitionContext]
)

const startTransition = useMemo(
function () {
if (ignoreTransitionContext) {
return startLocalTransition
}

return startContextTransition ?? startLocalTransition
},
[startContextTransition, startLocalTransition, ignoreTransitionContext]
)
const clearOnForget = oClearOnForget ?? cClearOnForget ?? false

const clearOnForget = useMemo(
function () {
return oClearOnForget ?? cClearOnForget ?? false
},
[oClearOnForget, cClearOnForget]
)

const promise = useMemo(
function () {
return query<T>(key, {
expiration: oExpiration,
fetcher: oFetcher,
stale: oStale,
removeOnError: oRemoveOnError,
fresh: oFresh,
})
},
[query, key, oExpiration, oFetcher, oStale, oRemoveOnError, oFresh]
)
const promise = query<T>(key, {
expiration: oExpiration,
fetcher: oFetcher,
stale: oStale,
removeOnError: oRemoveOnError,
fresh: oFresh,
})

const [data, setData] = useState<T>(use(promise))

Expand Down Expand Up @@ -177,10 +142,5 @@ export function useQueryBasic<T = unknown>(
]
)

return useMemo(
function (): BasicResource<T> {
return { data, isPending }
},
[data, isPending]
)
return { data, isPending }
}
4 changes: 1 addition & 3 deletions src/react/hooks/useQueryContext.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Context, type ContextValue } from 'query/react:context'
import { use, useDebugValue } from 'react'
import { use } from 'react'

export function useQueryContext(): ContextValue {
useDebugValue('useQueryContext')

return use(Context)
}
Loading