should you manually remove event listeners from onMount with onCleanup
Title pretty much sums it up. I see the primitives package says its done automatically, but I'm wondering if any cleanup is automatically for listeners set up on components in onMount, I know (or think) solid does some processing of event listeners in terms of event propagation for certain kinds of events, so wondering if it were to do something like this for disposal of listeners on component. thanks
6 Replies
Generally to stay on the safer side, I always do manual removal of events in onCleanup or otherwise
okay cool thanks, yea I been doing the same but wanted to check if actually necessary
Or just use the deferred events and enjoy the automatic cleanup.
great thank you, so you should manually cleanup if using
addEventListener
, just to clarify. Even if the owner is disposed, the event listener would leak?
And by deferred events, do you refer to handlers added as props to jsx with on...
e.g onClick={e=>...}
? cheersYes, onClick works by setting up listeners on the mountpoint and walking the target tree to find those tags that have an event internally bound to them.
okay cool thanks