Skip an optional-argument query
A component receives an optional identifier and must not fetch until it exists.
Redux Toolkit · Function
skipToken is an RTK Query value for conditionally disabling a query without weakening the endpoint argument type. Pass it instead of an unavailable argument to supported query hooks or selectors.
skipToken is a Redux Toolkit Query export used as a query argument for useQuery, useQueryState, or useQuerySubscription. It produces the same behavior as skip: true while allowing a possibly undefined argument to remain type-safe; selectors receiving it return an uninitialized state.
useQuery(queryArg | skipToken, options?)| Name | Type | Description |
|---|---|---|
arg | QueryArg | SkipToken | The endpoint query argument, or skipToken to prevent the query from running. |
options | UseQueryOptions | Optional hook settings; useQuery options can also contain skip: true. |
For query hooks, the normal query hook result with an uninitialized state while skipped; selectors passed skipToken return a default uninitialized state.
import { skipToken } from '@reduxjs/toolkit/query/react'
import { useGetPostQuery } from './api'
function MaybePost({ id }: { id?: number }) {
const { data, isUninitialized } = useGetPostQuery(id ?? skipToken)
return <div>{isUninitialized ? 'Choose a post' : data?.title}</div>
}Passes skipToken when id is absent, so the hook remains type-safe while the query is skipped.
A component receives an optional identifier and must not fetch until it exists.
A TypeScript endpoint requires a concrete argument, but the UI conditionally lacks one.
A selector should represent a disabled query without selecting cache data.
skipToken is a special RTK Query export used in place of a query argument. For the supported query hooks, it has the same effect as setting skip: true and is useful when the normal argument could be undefined.
Follow-up: How would you preserve endpoint argument types when an optional ID is available? Use id ?? skipToken, so the endpoint receives either its declared ID type or the special skip value.
Use skipToken as the argument to useQuery, useQueryState, or useQuerySubscription. A common pattern is useGetPostQuery(id ?? skipToken), which skips only when id is nullish.
Follow-up: What happens if the condition is represented by an empty string rather than null or undefined? The expression must encode that policy explicitly, such as condition ? value : skipToken.
RTK Query also accepts skipToken in query selectors. When supplied there, the selector returns a default uninitialized state, which lets code avoid selecting a value for a disabled query.
Follow-up: Why might a selector use this instead of conditionally calling a selector factory? It provides a stable, documented disabled-query result rather than attempting to select with an invalid cache argument.
skipuseQueryuseQueryStateuseQuerySubscriptionSkipToken