fix: remove paste event handler on unmount

This commit is contained in:
EETagent 2022-12-04 12:21:55 +01:00
parent 0516bf2a1a
commit f58d8bb01f

View file

@ -40,7 +40,7 @@
submit(); submit();
} }
const submit = async () => { const submit = async () => {
try { try {
await apiLogin({ applicationId, password: codeValueMobile }); await apiLogin({ applicationId, password: codeValueMobile });
goto('/dashboard'); goto('/dashboard');
@ -48,7 +48,7 @@
console.error(e); console.error(e);
} }
// alert('ApplicationId: ' + applicationId + '; Password: ' + codeValueMobile); // alert('ApplicationId: ' + applicationId + '; Password: ' + codeValueMobile);
} };
const onPaste = (e: ClipboardEvent) => { const onPaste = (e: ClipboardEvent) => {
e.preventDefault(); e.preventDefault();
@ -65,8 +65,11 @@
codeElementArray[0].focus(); codeElementArray[0].focus();
// Document on:paste // Document on:paste
document.onpaste = (e: ClipboardEvent) => { document.addEventListener('paste', onPaste);
onPaste(e);
return () => {
// this function is called when the component is destroyed
document.removeEventListener('paste', onPaste);
}; };
}); });
</script> </script>