From 469339ba3d6f637cb26d774e868b4ba69f4e6fe5 Mon Sep 17 00:00:00 2001 From: soleh45 <93110828+soleh45@users.noreply.github.com> Date: Sun, 17 Mar 2024 23:20:57 +0700 Subject: [PATCH] fix: clear dropdown on unmount (#114) * fix: when the user opens the content dropdown then the user immediately unmounts the component, the content is not reset so an error occurs, because the content is not reset and is on another thread * fix: delete double comma --------- Co-authored-by: soleh setiawan --- src/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/index.js b/src/index.js index ea2c9a8..cacd049 100644 --- a/src/index.js +++ b/src/index.js @@ -65,6 +65,13 @@ export const AutocompleteDropdown = memo( LogBox.ignoreLogs(['VirtualizedLists should never be nested']) }, []) + useEffect(() => { + // Do content cleaning when the component is unmounted + return () => { + setContent(undefined) + }; + }, []); + /** Set initial value */ useEffect(() => { if (!Array.isArray(dataSet) || selectedItem) {