1import { useCallback, useState } from 'react';
2import { identity } from 'lodash';
5 * Manages an immutable array of items.
7export default function useArray(initialItems = [], itemBuilder = identity) {
8 const [items, _setItems] = useState(initialItems);
10 const append = useCallback(
11 item => _setItems(items => [...items, itemBuilder(item)]),
12 [_setItems, itemBuilder]
15 const removeAt = useCallback(
18 const newItems = [...items.slice(0, i), ...items.slice(i + 1)];
24 const updateAt = useCallback(
32 ...items.slice(i + 1),
37 const clear = useCallback(() => _setItems([]), [_setItems]);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list