martixy
martixy
SSolidJS
Created by martixy on 5/1/2024 in #support
computations created outside a `createRoot` or `render` will never be disposed
Escaping reactivity contexts is presumably usually because of async operations. Well, I create this effect inside an event handler. My component is attached to a specific part of the DOM, creating a small island of reactivity. However the event in question is a keydown event attached to the document.
onMount(() => {
document.addEventListener('keydown', kbHandler)
})

onCleanup(() => {
document.removeEventListener('keydown', kbHandler)
})
onMount(() => {
document.addEventListener('keydown', kbHandler)
})

onCleanup(() => {
document.removeEventListener('keydown', kbHandler)
})
a) Is this the cause of the warning or am I mistaken? b) What is a good way to do this? Docs talk about delegated events that are attached to the document, but dispatched to the element (uncessary in this case, but whatever). But I tried <div onKeyDown={kbHandler}> and it won't fire my handler.
47 replies