You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(useList): new action upsert;
feat(useList): new action update;
feat(useList): new action updateFirst;
feat(useList): new action insertAt;
feat(useList): action remove renamed to removeAt (ref remained);
feat(useUpsert): useUpsert hook deprecated cause of duplicate functionality and bad naming;
Copy file name to clipboardExpand all lines: README.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -134,7 +134,7 @@
134
134
-[`useStateList`](./docs/useStateList.md)— circularly iterates over an array. [![][img-demo]](https://codesandbox.io/s/bold-dewdney-pjzkd)
135
135
-[`useToggle` and `useBoolean`](./docs/useToggle.md)— tracks state of a boolean. [![][img-demo]](https://codesandbox.io/s/focused-sammet-brw2d)
136
136
-[`useCounter` and `useNumber`](./docs/useCounter.md)— tracks state of a number. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/state-usecounter--demo)
137
-
-[`useList`](./docs/useList.md) and [`useUpsert`](./docs/useUpsert.md)— tracks state of an array. [![][img-demo]](https://codesandbox.io/s/wonderful-mahavira-1sm0w)
137
+
-[`useList`](./docs/useList.md)~and [`useUpsert`](./docs/useUpsert.md)~— tracks state of an array. [![][img-demo]](https://codesandbox.io/s/wonderful-mahavira-1sm0w)
138
138
-[`useMap`](./docs/useMap.md)— tracks state of an object. [![][img-demo]](https://codesandbox.io/s/quirky-dewdney-gi161)
139
139
-[`useStateValidator`](./docs/useStateValidator.md)— tracks state of an object. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/state-usestatevalidator--demo)
140
140
-[`useMultiStateValidator`](./docs/useMultiStateValidator.md)— alike the `useStateValidator`, but tracks multiple states at a time. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/state-usemultistatevalidator--demo)
Copy file name to clipboardExpand all lines: docs/useList.md
+43-2
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,19 @@
1
1
# `useList`
2
2
3
-
React state hook that tracks a value of an array.
3
+
Tracks an array and provides methods to modify it.
4
+
To cause component re-render you have to use these methods instead of direct interaction with array - it won't cause re-render.
5
+
6
+
We can ensure that actions object and actions itself will not mutate or change between renders, so there is no need to add it to useEffect dependencies and safe to pass them down to children.
7
+
8
+
**Note:**`remove` action is deprecated and actually is a copy of `removeAt` action. Within closest updates it will gain different functionality.
-**`set`**_`: (list: T[]) => void;`_ — Set new list instead old one;
58
+
-**`push`**_`: (...items: T[]) => void;`_ — Add item(s) at the end of list;
59
+
-**`updateAt`**_`: (index: number, item: T) => void;`_ — Replace item at given position. If item at given position not exists it will be set;
60
+
-**`insertAt`**_`: (index: number, item: T) => void;`_ — Insert item at given position, all items to the right will be shifted;
61
+
-**`update`**_`: (predicate: (a: T, b: T) => boolean, newItem: T) => void;`_ — Replace all items that matches predicate with given one;
62
+
-**`updateFirst`**_`: (predicate: (a: T, b: T) => boolean, newItem: T) => void;`_ — Replace first item matching predicate with given one;
63
+
-**`upsert`**_`: (predicate: (a: T, b: T) => boolean, newItem: T) => void;`_ — Like `updateFirst` bit in case of predicate miss - pushes item to the list;
64
+
-**`sort`**_`: (compareFn?: (a: T, b: T) => number) => void;`_ — Sort list with given sorting function;
65
+
-**`filter`**_`: (callbackFn: (value: T, index?: number, array?: T[]) => boolean, thisArg?: any) => void;`_ — Same as native Array's method;
66
+
-**`removeAt`**_`: (index: number) => void;`_ — Removes item at given position. All items to the right from removed will be shifted;
67
+
-**`remove`**_`: (index: number) => void;`_ —_**DEPRECATED:**_ Use removeAt method instead;
68
+
-**`clear`**_`: () => void;`_ — Make the list empty;
69
+
-**`reset`**_`: () => void;`_ — Reset list to initial value;
0 commit comments