From 0db344e0196e3d797354297a503fd1b3fb392b0b Mon Sep 17 00:00:00 2001 From: kofiarkoh Date: Sun, 1 Dec 2024 21:05:57 -0500 Subject: [PATCH] reset options list to initial state when search input is cleared --- src/hooks/use-search.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/hooks/use-search.ts b/src/hooks/use-search.ts index 415beb8..b94e5f3 100644 --- a/src/hooks/use-search.ts +++ b/src/hooks/use-search.ts @@ -25,8 +25,12 @@ export const useSearch = ({ TFlatList | TSectionList >(initialOptions); + const resetOptionsToDefault = (options: TFlatList | TSectionList) => { + setFilteredOptions(options); + }; + useEffect(() => { - setFilteredOptions(initialOptions); + resetOptionsToDefault(initialOptions); return () => {}; }, [initialOptions]); @@ -83,6 +87,9 @@ export const useSearch = ({ if (searchValue) { onSearch(searchValue); } + else{ + resetOptionsToDefault(initialOptions) + } }, [onSearch, searchValue]); return {