Skip to content

Commit

Permalink
refactor(useListFilter): rename items to filteredItems
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuan committed Aug 14, 2024
1 parent 220a4b9 commit 43a33ab
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/components/useList/hooks/useListFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function useListFilter<T>({
const filterRef = React.useRef<HTMLInputElement>(null);
const [filter, setFilter] = React.useState(initialFilterValue);
const [prevItems, setPrevItems] = React.useState(externalItems);
const [items, setItems] = React.useState(externalItems);
const [filteredItems, setFilteredItems] = React.useState(externalItems);

const filterItemsFn = React.useCallback(
(nextFilterValue: string, items: ListItemType<T>[]) => {
Expand All @@ -68,13 +68,13 @@ export function useListFilter<T>({
);

if (externalItems !== prevItems) {
setItems(filterItemsFn(filter, externalItems));
setFilteredItems(filterItemsFn(filter, externalItems));
setPrevItems(externalItems);
}

const debouncedFn = React.useCallback(
debounce((value) => setItems(filterItemsFn(value, externalItems)), debounceTimeout),
[setItems, filterItemsFn, externalItems, debounceTimeout],
debounce((value) => setFilteredItems(filterItemsFn(value, externalItems)), debounceTimeout),
[setFilteredItems, filterItemsFn, externalItems, debounceTimeout],
);

const {onFilterUpdate, reset} = React.useMemo(() => {
Expand All @@ -96,7 +96,7 @@ export function useListFilter<T>({
filterRef,
filter,
reset,
items,
items: filteredItems,
onFilterUpdate,
};
}

0 comments on commit 43a33ab

Please sign in to comment.