Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: export default hydration methods for easier extension in `dehyd…
…rateOptions` (#4751)

* export default hydration metods to allow for easier extending

* pretty

Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
  • Loading branch information
nahtnam and TkDodo committed Jan 8, 2023
1 parent 4853ace commit 228b1f0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
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

0 comments on commit 228b1f0

Please sign in to comment.