As normal, the input has an onChange
event to detect change (but by character)
const handleChange = event => {
setInputValue(event.target.value);
//When typing "asking" => would be "a" "as" "ask", ....
};
So what I want to do is when scan a bar code by hardware device into an input, then call an action to server only if have scanned the word completely. The problem here is it listen the input change character by character
React.useEffect(() => {
if (!!inputValue.length) {
handleScan();
}
}, [inputValue]);
Those code will call handleScan
on each character that typing in the input, would end up with many time of calling handleScan()
. I expect to call once
Is there any way to wait a bit until the input completely have a word (Ex: "BarCode"), then do an action?
Any help would be appreciated.