Last active
September 18, 2020 23:55
-
-
Save HanggiAnggono/cd5fa6b107b85a9d10c1b40428434d5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BarcodeReader = ({ onScan }) => { | |
const [str, setStr] = useState('') | |
function handleReceive(scanData) { | |
const key = scanData.key | |
// if it's enter key then perform onScan | |
if (key === 'Enter' && onScan) { | |
onScan(str) | |
setStr('') | |
} else { | |
setStr(str + key) | |
} | |
} | |
return ( | |
<ReactBarcodeReader | |
minLength={0} | |
preventDefault | |
stopPropagation | |
onReceive={handleReceive} | |
/> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment