replaceData
Category
Tags
Export size
min 0.12 kB · gzip 0.12 kB
See also
Replaces context.data wholesale with the given items, preserving the original single-vs-array shape. This is the explicit inverse of getDataIsArray: get the data as an array, modify or replace the items, then write them back.
ts
import { replaceData } from 'feathers-utils/utils';Example
ts
import { getDataIsArray, replaceData } from 'feathers-utils/utils'
const { data } = getDataIsArray(context)
const next = data.map((item) => ({ ...item, slug: slugify(item.name) }))
replaceData(context, next)Type declaration
Show Type Declarations
ts
/**
* Replaces `context.data` wholesale with the given items, preserving the original
* single-vs-array shape. This is the explicit inverse of `getDataIsArray`: get the
* data as an array, modify or replace the items, then write them back.
*
* @example
* ```ts
*
*
* const { data } = getDataIsArray(context)
* const next = data.map((item) => ({ ...item, slug: slugify(item.name) }))
* replaceData(context, next)
* ```
*
* @see https://utils.feathersjs.com/utils/replace-data.html
*/
export declare function replaceData<H extends HookContext = HookContext>(
context: H,
data: DataSingleHookContext<H>[],
): H| Argument | Type | Description |
|---|---|---|
| context | H | |
| data | DataSingleHookContext<H>[] |
