Skip to main content

Interface: DataMethods<Data, Context>

Type Parameters

Data = any

Context = any

Properties

prepend()

prepend: (data) => void

Prepends additional items to the existing data in the list, while preserving the scroll position.

Parameters

data

Data[]

The data to prepend.

Returns

void


append()

append: (data, scrollToBottom?) => void

Appends additional items to the existing data in the list, while optionally updating the scroll position. See the AutoscrollToBottom type for more information.

Parameters

data

Data[]

The data to append.

scrollToBottom?

AutoscrollToBottom<Data, Context>

Specifies the behavior when the list is scrolled to the bottom. You can pass a boolean, a ScrollBehavior, or a function that returns a ScrollBehavior.

Returns

void


map()

map: (callbackfn, autoscrollToBottomBehavior?) => void

Updates the data in the list by applying a mapping function to each item. Optionally, you can specify a scroll behavior if the state change displaces the list (for example, if the item size increases).

Parameters

callbackfn

(data, index) => Data

A function that maps the data items.

autoscrollToBottomBehavior?

Specifies the behavior to use to scroll to the bottom if necessary.

ScrollBehavior | { location: () => ItemLocation | null | undefined; }

Returns

void


findAndDelete()

findAndDelete: (predicate) => void

Deletes items from the list data that match the predicate.

Parameters

predicate

(item, index) => boolean

Returns

void


findIndex()

findIndex: (predicate) => number

Finds the index of the first item that matches the predicate. If no elements satisfy the testing function, -1 is returned.

Parameters

predicate

(item, index, data) => boolean

Returns

number


find()

find: (predicate) => undefined | Data

Finds the first item that matches the predicate. If no elements satisfy the testing function, undefined is returned.

Parameters

predicate

(item, index, data) => boolean

Returns

undefined | Data


replace()

replace: (data, options?) => void

Completely replaces the data in the list with the new data. Optionally, you can specify an initial scroll location after the data has been replaced. See the ItemLocation type for more information. Setting the purgeItemSizes flag to true will clear the item size cache and force the list to remeasure the items. The suppressItemMeasure flag will prevent the list from measuring the items after the data has been replaced.

Parameters

data

Data[]

The data to replace.

options?

the location to scroll to after the data has been replaced and whether to purge the item sizes.

initialLocation

ItemLocation

purgeItemSizes

boolean

suppressItemMeasure

boolean

Returns

void


insert()

insert: (data, offset, scrollToBottom?) => void

Inserts the provided data at the specified offset, optionally updating the scroll position.

Parameters

data

Data[]

The data to append.

offset

number

The index that the first item in the data will be inserted at. e.g. [1,2,3] with offset 10 will insert the data at index 10, 11, and 12 and shift the rest of the existing data.

scrollToBottom?

AutoscrollToBottom<Data, Context>

Specifies the behavior when the list is scrolled to the bottom. You can pass a boolean, a ScrollBehavior, or a function that returns a ScrollBehavior.

Returns

void


deleteRange()

deleteRange: (offset, count) => void

Deletes a range of items from the list data.

Parameters

offset

number

The index of the first item to delete.

count

number

The number of items to delete.

Returns

void


batch()

batch: (callback, scrollToBottom?) => void

Batches the data operations in the provided callback in a single render cycle.

Parameters

callback

() => void

The callback that performs the data operations.

scrollToBottom?

AutoscrollToBottom<Data, Context>

Specifies the behavior when the list is scrolled to the bottom. You can pass a boolean, a ScrollBehavior, or a function that returns a ScrollBehavior.

Returns

void


get()

get: () => Data[]

Gets a shallow copy of the current data in the list.

Returns

Data[]


getCurrentlyRendered()

getCurrentlyRendered: () => Data[]

Gets the currently rendered data items.

Returns

Data[]