S
SolidJS8mo ago
Max

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
REEEEE
REEEEE8mo ago
Generally to stay on the safer side, I always do manual removal of events in onCleanup or otherwise
Max
MaxOP8mo ago
okay cool thanks, yea I been doing the same but wanted to check if actually necessary
Alex Lohr
Alex Lohr8mo ago
Or just use the deferred events and enjoy the automatic cleanup.
Max
MaxOP8mo ago
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=>...}? cheers
Alex Lohr
Alex Lohr8mo ago
Yes, 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.
Max
MaxOP8mo ago
okay cool thanks
Want results from more Discord servers?
Add your server