Skip to content

Commit

Permalink
fix(ComboBox): save onInputChange in ref
Browse files Browse the repository at this point in the history
  • Loading branch information
emyarod committed Apr 30, 2021
1 parent 7eaad2b commit f9efcc7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/react/src/components/ComboBox/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -147,10 +148,10 @@ const ComboBox = (props) => {
};

useEffect(() => {
if (onInputChange) {
onInputChange(inputValue);
if (savedOnInputChange.current) {
savedOnInputChange.current(inputValue);
}
}, [onInputChange, inputValue]);
}, [inputValue]);

const handleSelectionClear = () => {
if (textInput?.current) {
Expand Down

0 comments on commit f9efcc7

Please sign in to comment.