MCPcopy Create free account
hub / github.com/TanStack/query / addToArray

Function addToArray

packages/query-core/src/utils.ts:601–612  ·  view source on GitHub ↗
(
  items: Array<T>,
  item: T,
  max?: number,
  prepend?: boolean,
)

Source from the content-addressed store, hash-verified

599 * @returns A new array with `item` added.
600 */
601export function addToArray<T>(
602 items: Array<T>,
603 item: T,
604 max?: number,
605 prepend?: boolean,
606): Array<T> {
607 const newItems = prepend ? [item, ...items] : [...items, item]
608 if (max && newItems.length > max) {
609 return prepend ? newItems.slice(0, max) : newItems.slice(-max)
610 }
611 return newItems
612}
613
614/**
615 * Sentinel value that can be passed as a query's `queryFn` to conditionally disable the query (equivalent

Callers 3

fetchPageFunction · 0.90
utils.test-d.tsxFile · 0.90
utils.test.tsxFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected