From 7eaad2b537f89bc2311cabe035e4619b88c16ea9 Mon Sep 17 00:00:00 2001 From: emyarod Date: Mon, 5 Apr 2021 17:13:24 -0500 Subject: [PATCH 1/2] fix(ComboBox): add missing dependencies to useEffect --- packages/react/src/components/ComboBox/ComboBox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react/src/components/ComboBox/ComboBox.js b/packages/react/src/components/ComboBox/ComboBox.js index 47e3076d78af..08bb87369a2d 100644 --- a/packages/react/src/components/ComboBox/ComboBox.js +++ b/packages/react/src/components/ComboBox/ComboBox.js @@ -150,7 +150,7 @@ const ComboBox = (props) => { if (onInputChange) { onInputChange(inputValue); } - }); + }, [onInputChange, inputValue]); const handleSelectionClear = () => { if (textInput?.current) { From 1ced73fb9a814b26820ef9694e7474408ada754c Mon Sep 17 00:00:00 2001 From: emyarod Date: Fri, 30 Apr 2021 10:45:09 -0500 Subject: [PATCH 2/2] fix(ComboBox): save onInputChange in ref --- packages/react/src/components/ComboBox/ComboBox.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/react/src/components/ComboBox/ComboBox.js b/packages/react/src/components/ComboBox/ComboBox.js index 08bb87369a2d..a356351cea2e 100644 --- a/packages/react/src/components/ComboBox/ComboBox.js +++ b/packages/react/src/components/ComboBox/ComboBox.js @@ -113,6 +113,7 @@ const ComboBox = (props) => { ); const [prevSelectedItem, setPrevSelectedItem] = useState(null); const [doneInitialSelectedItem, setDoneInitialSelectedItem] = useState(null); + const savedOnInputChange = useRef(onInputChange); if (!doneInitialSelectedItem || prevSelectedItem !== selectedItem) { setDoneInitialSelectedItem(true); @@ -147,10 +148,14 @@ const ComboBox = (props) => { }; useEffect(() => { - if (onInputChange) { - onInputChange(inputValue); + savedOnInputChange.current = onInputChange; + }, [onInputChange]); + + useEffect(() => { + if (savedOnInputChange.current) { + savedOnInputChange.current(inputValue); } - }, [onInputChange, inputValue]); + }, [inputValue]); const handleSelectionClear = () => { if (textInput?.current) {