Add checkboxes for documents table
Helps #167 Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
committed by
Sacha Al Himdani
parent
25b330f948
commit
a4606f95f5
@@ -1,3 +1,4 @@
|
||||
export { usePageTitle } from "./usePageTitle";
|
||||
export { useToggle } from "./useToggle";
|
||||
export { useRefSync } from "./useRefSync";
|
||||
export { useList } from "./useList";
|
||||
|
||||
25
packages/hooks/src/useList.ts
Normal file
25
packages/hooks/src/useList.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { useCallback, useState } from "react";
|
||||
|
||||
export function useList<T>(items: T[]) {
|
||||
const [list, setList] = useState(items);
|
||||
const push = useCallback(
|
||||
(item: T) => setList((prev) => [...prev, item]),
|
||||
[],
|
||||
);
|
||||
const remove = useCallback(
|
||||
(item: T) => setList((prev) => prev.filter((i) => i !== item)),
|
||||
[],
|
||||
);
|
||||
const toggle = useCallback(
|
||||
(item: T) =>
|
||||
setList((prev) =>
|
||||
prev.includes(item)
|
||||
? prev.filter((i) => i !== item)
|
||||
: [...prev, item],
|
||||
),
|
||||
[],
|
||||
);
|
||||
const reset = useCallback((items: T[]) => setList(items), []);
|
||||
const clear = useCallback(() => setList([]), []);
|
||||
return { list, push, remove, toggle, reset, clear };
|
||||
}
|
||||
Reference in New Issue
Block a user