Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export default hydration methods for easier extension in dehydrateOptions #4751

Merged
merged 3 commits into from Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/react/reference/hydration.md
Expand Up @@ -33,11 +33,13 @@ const dehydratedState = dehydrate(queryClient, {
- This function is called for each mutation in the cache
- Return `true` to include this mutation in dehydration, or `false` otherwise
- The default version only includes paused mutations
- If you would like to extend the function while retaining the previous behavior, import and execute `defaultShouldDehydrateMutation` as part of the return statement
- `shouldDehydrateQuery: (query: Query) => boolean`
- Optional
- This function is called for each query in the cache
- Return `true` to include this query in dehydration, or `false` otherwise
- The default version only includes successful queries, do `shouldDehydrateQuery: () => true` to include all queries
- If you would like to extend the function while retaining the previous behavior, import and execute `defaultShouldDehydrateQuery` as part of the return statement

**Returns**

Expand Down
4 changes: 2 additions & 2 deletions packages/query-core/src/hydration.ts
Expand Up @@ -65,11 +65,11 @@ function dehydrateQuery(query: Query): DehydratedQuery {
}
}

function defaultShouldDehydrateMutation(mutation: Mutation) {
export function defaultShouldDehydrateMutation(mutation: Mutation) {
return mutation.state.isPaused
}

function defaultShouldDehydrateQuery(query: Query) {
export function defaultShouldDehydrateQuery(query: Query) {
return query.state.status === 'success'
}

Expand Down
7 changes: 6 additions & 1 deletion packages/query-core/src/index.ts
Expand Up @@ -23,7 +23,12 @@ export {
} from './utils'
export type { MutationFilters, QueryFilters, Updater } from './utils'
export { isCancelledError } from './retryer'
export { dehydrate, hydrate } from './hydration'
export {
dehydrate,
hydrate,
defaultShouldDehydrateMutation,
defaultShouldDehydrateQuery,
} from './hydration'

// Types
export * from './types'
Expand Down