Skip to content

Latest commit

 

History

History
30 lines (18 loc) · 870 Bytes

signal-from-event.md

File metadata and controls

30 lines (18 loc) · 870 Bytes

signalFromEvent(target, eventName, listenerOptions?)

Returns an AbortSignal that aborts when the event is dispatched. This lets abort an operation following an event.

// Abort request when the user clicks the cancel button
void fetch('https://example.com', {
	signal: signalFromEvent(cancelButton, 'click')
});

target

Type: EventTarget

The target to attach the listener to. This can be any Element or other object that implements the EventTarget interface.

eventName

Type: string

The name of the event to listen for.

options

Type: object

Options to pass to the addEventListener method (except once, which is always set to true). This can be used to specify the capture option or passive option or to specify a signal.