replaceResult
Category
Tags
Export size
min 0.57 kB · gzip 0.32 kB
See also
Replaces context.result (and/or context.dispatch) wholesale with the given items, preserving the original shape: single item, array, or paginated { data }. This is the explicit inverse of getResultIsArray.
ts
import { replaceResult } from 'feathers-utils/utils';Example
ts
import { getResultIsArray, replaceResult } from 'feathers-utils/utils'
const { result } = getResultIsArray(context)
replaceResult(context, result.filter((item) => item.public))Type declaration
Show Type Declarations
ts
export type ReplaceResultOptions = {
/**
* Also (or only) write to `context.dispatch`. `true` writes dispatch, `'both'`
* writes both `result` and `dispatch`. When dispatch is requested and not yet
* present, it is seeded from a clone of `context.result`.
*/
dispatch?: DispatchOption
}
/**
* Replaces `context.result` (and/or `context.dispatch`) wholesale with the given
* items, preserving the original shape: single item, array, or paginated `{ data }`.
* This is the explicit inverse of `getResultIsArray`.
*
* @example
* ```ts
*
*
* const { result } = getResultIsArray(context)
* replaceResult(context, result.filter((item) => item.public))
* ```
*
* @see https://utils.feathersjs.com/utils/replace-result.html
*/
export declare function replaceResult<H extends HookContext = HookContext>(
context: H,
result: ResultSingleHookContext<H>[],
options?: ReplaceResultOptions,
): H| Argument | Type | Description |
|---|---|---|
| context | H | |
| result | ResultSingleHookContext<H>[] | |
| options | ReplaceResultOptions |
