fix: clear timeout in onMount return function

This commit is contained in:
Eric Liu 2020-07-24 17:18:23 -07:00
commit fff54a19eb
3 changed files with 23 additions and 21 deletions

View file

@ -17,19 +17,18 @@
const dispatch = createEventDispatcher();
$: open = true;
$: timeoutId = undefined;
let open = true;
let timeoutId = undefined;
onMount(() => {
if (timeout) {
timeoutId = window.setTimeout(() => {
timeoutId = setTimeout(() => {
open = false;
}, timeout);
}
return () => {
window.clearTimeout(timeoutId);
timeoutId = undefined;
clearTimeout(timeoutId);
};
});
</script>