qwik icon indicating copy to clipboard operation
qwik copied to clipboard

[✨] Remove Event Listener after event is invoked once

Open theonlychase opened this issue 2 years ago • 3 comments

Is your feature request related to a problem?

The problem I am having is not being able to remove an event listener after it is invoked once, either by setting it on the element itself, or by creating an event using the useOn hook.

Describe the solution you'd like

The ability to set any of the event listener options, such as { once: true }. The event listener would automatically be removed after being invoked once.

Describe alternatives you've considered

As an example, I am currently using state to handle a window onScroll event that I only want triggered once based on the scroll position.

Additional context

Another option is using an intersection observer. I understand there is useVisibleTask?(), which can use an observer under the hood, but there is no way to set any of the Intersection Observer Options, or see the properties on the entry itself, such as the intersectionRatio. If the component/element is above the fold on page load, that Javascript gets loaded right away, which I want to avoid.

theonlychase avatar Mar 21 '23 17:03 theonlychase

you can add an attribute to the element and check the value

PatrickJS avatar May 06 '24 17:05 PatrickJS

@theonlychase is it solved?

gioboa avatar Oct 14 '24 12:10 gioboa

Hello @theonlychase. Please provide the missing information requested above. Issues marked with STATUS-2: missing info will be automatically closed if they have no activity within 14 days. Thanks 🙏

github-actions[bot] avatar Oct 14 '24 12:10 github-actions[bot]