onCleanup
Edit this pageonCleanup
registers a cleanup method that executes on disposal or recalculation fo the current reactive scopes.
Can be used in any Component or Effect to clean up any side effects that could be left behind when the component is removed from the page.
Without the onCleanup
function, the event listener would remain attached to the document even after the component is removed from the page.
This can cause memory leaks and other issues.