Skip to content

Commit

Permalink
Merge pull request #98 from azeezat/fix/reset-options-on-search-input…
Browse files Browse the repository at this point in the history
…-clear

reset options list to initial state when search input is cleared
  • Loading branch information
azeezat authored Dec 15, 2024
2 parents 5ad0b8c + 0db344e commit e39c8be
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/hooks/use-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ export const useSearch = ({
TFlatList | TSectionList
>(initialOptions);

const resetOptionsToDefault = (options: TFlatList | TSectionList) => {
setFilteredOptions(options);
};

useEffect(() => {
setFilteredOptions(initialOptions);
resetOptionsToDefault(initialOptions);
return () => {};
}, [initialOptions]);

Expand Down Expand Up @@ -83,6 +87,9 @@ export const useSearch = ({
if (searchValue) {
onSearch(searchValue);
}
else{
resetOptionsToDefault(initialOptions)
}
}, [onSearch, searchValue]);

return {
Expand Down

0 comments on commit e39c8be

Please sign in to comment.