diff --git a/src/useList.ts b/src/useList.ts index 1388338db5..46b4e0a42c 100644 --- a/src/useList.ts +++ b/src/useList.ts @@ -2,6 +2,7 @@ import {useState} from 'react'; export interface Actions { set: (list: T[]) => void; + updateAt: (index: number, item: T) => void; push: (item: T) => void; filter: (fn: (value: T) => boolean) => void; sort: (fn?: (a: T, b: T) => number) => void; @@ -12,6 +13,11 @@ const useList = (initialList: T[] = []): [T[], Actions] => { return [list, { set, + updateAt: (index, entry) => set([ + ...list.slice(0, index), + entry, + ...list.slice(index + 1) + ]), push: (entry) => set([...list, entry]), filter: (fn) => set(list.filter(fn)), sort: (fn?) => set([...list].sort(fn)),