The LiveSocket instance that the hook is attached to.
The beforeUpdate callback.
Called when the element is about to be updated in the DOM. Note: any call here must be synchronous as the operation cannot be deferred or cancelled.
The destroyed callback.
Called when the element has been removed from the page, either by a parent update, or by the parent being removed entirely.
The disconnected callback.
Called when the element's parent LiveView has disconnected from the server.
Allows to register a callback to be called when an event is received from the server.
This is used to handle pushEvent calls from the server. The callback is called with the payload from the server.
The event name.
The callback to call when the event is received.
A reference to the callback, which can be used in removeHandleEvent to remove the callback.
Returns an object with methods to manipulate the DOM and execute JavaScript. The applied changes integrate with server DOM patching.
The mounted callback.
Called when the element has been added to the DOM and its server LiveView has finished mounting.
Pushes an event to the server and invokes a callback with the server's reply.
Note: this version silently ignores push errors. Use the promise-returning version to handle errors.
The event name.
The payload to send to the server. Defaults to an empty object.
A callback to handle the server's reply.
Pushes an event to the server and returns a Promise that resolves with the server's reply.
The promise will be rejected in case of errors such as a disconnected state, timeout, or the server rejecting the event.
The event name.
Optionalpayload: anyThe payload to send to the server. Defaults to an empty object.
A promise that fulfills or rejects with the server's reply.
Pushes a targeted event to the server and invokes a callback with the server's reply.
It sends the event to the LiveComponent or LiveView the selectorOrTarget is defined in,
where its value can be either a query selector, an actual DOM element, or a CID (component id)
returned by the @myself assign.
If the selector matches multiple elements, the event is sent to all of them, even if they belong to the same LiveComponent or LiveView.
Note: this version silently ignores push errors. Use the promise-returning version to handle errors.
Pushes a targeted event to the server and returns a Promise that resolves with the server's reply.
It sends the event to the LiveComponent or LiveView the selectorOrTarget is defined in,
where its value can be either a query selector, an actual DOM element, or a CID (component id)
returned by the @myself assign.
If the selector matches multiple elements, the event is sent to all of them,
even if they belong to the same LiveComponent or LiveView.
Because of this, it returns a single promise that matches the return value of
Promise.allSettled().
Individual fulfilled values are of the format { reply, ref }, where reply is the server's reply.
The individual promises will be rejected in case of errors such as a disconnected state, timeout, or the server rejecting the event.
The selector, element, or CID to target.
The event name.
Optionalpayload: objectThe payload to send to the server. Defaults to an empty object.
A promise that resolves when the event has been handled by all targets.
The reconnected callback.
Called when the element's parent LiveView has reconnected to the server.
Removes a callback registered with handleEvent.
The reference to the callback to remove.
The updated callback.
Called when the element has been updated in the DOM by the server.
Allows to trigger a live file upload.
The upload name corresponding to the Phoenix.LiveView.allow_upload/3 call.
The files to upload.
Allows to trigger a live file upload to a specific target.
The target to upload the files to.
The upload name corresponding to the Phoenix.LiveView.allow_upload/3 call.
The files to upload.
Base class for LiveView hooks. Users extend this class to define their hooks.
Example:
The
thiscontext within the hook methods (mounted, updated, custom methods, etc.) will refer to the hook instance, providing access tothis.el,this.liveSocket,this.pushEvent(), etc., as well as any properties or methods defined on the subclass.