Skip to content
On this page

useIpcRendererOn

Category
Package
@vueuse/electron
Last Changed
7 months ago

Use ipcRenderer.on with ease and ipcRenderer.removeListener automatically on unmounted. available in add-on @vueuse/electron

Usage

import { useIpcRendererOn } from '@vueuse/electron'

// enable nodeIntegration if you don't provide ipcRenderer explicitly
// @see: https://www.electronjs.org/docs/api/webview-tag#nodeintegration
// remove listener automatically on unmounted
useIpcRendererOn('custom-event', (event, ...args) => {
  console.log(args)
})
import { useIpcRendererOn } from '@vueuse/electron'

// enable nodeIntegration if you don't provide ipcRenderer explicitly
// @see: https://www.electronjs.org/docs/api/webview-tag#nodeintegration
// remove listener automatically on unmounted
useIpcRendererOn('custom-event', (event, ...args) => {
  console.log(args)
})

Type Declarations

Show Type Declarations
/**
 * Listens to channel, when a new message arrives listener would be called with listener(event, args...).
 * [ipcRenderer.removeListener](https://www.electronjs.org/docs/api/ipc-renderer#ipcrendererremovelistenerchannel-listener) automatically on unmounted.
 *
 * You need to provide `ipcRenderer` to this function.
 *
 * @see https://www.electronjs.org/docs/api/ipc-renderer#ipcrendereronchannel-listener
 * @export
 * @param {IpcRenderer} ipcRenderer
 * @param {string} channel
 * @param {IpcRendererListener} listener
 * @returns {IpcRenderer}
 */
export declare function useIpcRendererOn(
  ipcRenderer: IpcRenderer,
  channel: string,
  listener: IpcRendererListener
): IpcRenderer
/**
 * Listens to channel, when a new message arrives listener would be called with listener(event, args...).
 * [ipcRenderer.removeListener](https://www.electronjs.org/docs/api/ipc-renderer#ipcrendererremovelistenerchannel-listener) automatically on unmounted.
 *
 * `ipcRenderer` will be automatically gotten.
 *
 * @see https://www.electronjs.org/docs/api/ipc-renderer#ipcrendereronchannel-listener
 * @export
 * @param {string} channel
 * @param {IpcRendererListener} listener
 * @returns {IpcRenderer}
 */
export declare function useIpcRendererOn(
  channel: string,
  listener: IpcRendererListener
): IpcRenderer
/**
 * Listens to channel, when a new message arrives listener would be called with listener(event, args...).
 * [ipcRenderer.removeListener](https://www.electronjs.org/docs/api/ipc-renderer#ipcrendererremovelistenerchannel-listener) automatically on unmounted.
 *
 * You need to provide `ipcRenderer` to this function.
 *
 * @see https://www.electronjs.org/docs/api/ipc-renderer#ipcrendereronchannel-listener
 * @export
 * @param {IpcRenderer} ipcRenderer
 * @param {string} channel
 * @param {IpcRendererListener} listener
 * @returns {IpcRenderer}
 */
export declare function useIpcRendererOn(
  ipcRenderer: IpcRenderer,
  channel: string,
  listener: IpcRendererListener
): IpcRenderer
/**
 * Listens to channel, when a new message arrives listener would be called with listener(event, args...).
 * [ipcRenderer.removeListener](https://www.electronjs.org/docs/api/ipc-renderer#ipcrendererremovelistenerchannel-listener) automatically on unmounted.
 *
 * `ipcRenderer` will be automatically gotten.
 *
 * @see https://www.electronjs.org/docs/api/ipc-renderer#ipcrendereronchannel-listener
 * @export
 * @param {string} channel
 * @param {IpcRendererListener} listener
 * @returns {IpcRenderer}
 */
export declare function useIpcRendererOn(
  channel: string,
  listener: IpcRendererListener
): IpcRenderer

Source

SourceDocs

Contributors

Anthony Fu
ArcherGu

Changelog

No recent changes
useIpcRendererOn has loaded