[✨] Remove Event Listener after event is invoked once #3464
Labels
STATUS-2: missing info
Incomplete issue/pr template or missing important information
STATUS-3: no response
The issue / PR creator has not responded for a while
TYPE: enhancement
New feature or request
Milestone
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.The text was updated successfully, but these errors were encountered: