Last active
December 12, 2024 09:36
-
-
Save akbarjondev/47e4bdbea7b06144fd7ca74e00de36de to your computer and use it in GitHub Desktop.
Adds Event listeners to HTML elements and safely removes them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function bind(target, { type, listener, options }) { | |
target.addEventListener(type, listener, options); | |
return function unbind() { | |
target.removeEventListener(type, listener, options); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage