Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TanStack · Const

defaultShouldDehydrateQuery

defaultShouldDehydrateQuery is TanStack Query's default predicate for selecting queries during dehydration. It includes only queries with a successful status.

How it works

This predicate receives each query considered during dehydration and returns whether it should be included. Its default rule accepts only queries whose status is "success", so custom predicates can call it first to preserve that behavior while adding other conditions.

Syntax

function defaultShouldDehydrateQuery(query: Query): boolean;

Parameters

NameTypeDescription
queryQueryThe Query whose dehydration eligibility is evaluated.

Returns

boolean: true when the query's status is 'success'.

Key points

  • It is the built-in query-selection predicate used when dehydrate determines its default dehydrated contents.
  • Its sole input is the Query currently being evaluated.
  • A successful query produces true, making it eligible for default dehydration.
  • The default policy excludes queries whose status is not successful.

Common mistakes

  • Queries in other statuses are excluded unless dehydrate receives a custom shouldDehydrateQuery predicate.

Example: Extend the default dehydration predicate

import { dehydrate, defaultShouldDehydrateQuery } from '@tanstack/query-core'

const state = dehydrate(queryClient, {
  shouldDehydrateQuery: (query) =>
    defaultShouldDehydrateQuery(query) || query.state.status === 'error',
})

Creates dehydrated state that keeps the default successful queries and additionally includes failed queries.

When to use it

Select successful queries for transfer to the client

Server-side rendering

Extend the default rule to include failed queries

Error-aware hydration

Build status-based inclusion logic around the built-in predicate

Custom dehydration policies

Interview questions

QWhat does defaultShouldDehydrateQuery do?

It is the default predicate used by dehydrate to decide whether a query is included in dehydrated state. It returns true only when the query status is "success".

Follow-up: How would you include errors while retaining the default behavior? Call this predicate and OR its result with a condition for the error status.

QWhat are its parameter and return types?

The function accepts one Query argument and returns a boolean. A true result means the query meets the default dehydration rule.

Follow-up: Why might a caller avoid replacing the predicate with an unconditional true? Because that changes the default filtering and includes queries that are not successful.

QHow can the default rule be extended?

dehydrate uses this predicate as its default query-selection rule. To extend the rule, provide shouldDehydrateQuery and invoke the default predicate inside the custom function.

Follow-up: What additional behavior can the custom predicate implement? It can selectively include other query statuses, such as errors, while preserving successful-query inclusion.

  • dehydrate
  • DehydrateOptions
  • shouldDehydrateQuery

Source: defaultShouldDehydrateQuery. Checked 2026-10-16.