electron-use-ipc-listener
v1.0.0
Published
React Hook for Electron that simplifies IPC routine
Downloads
30
Maintainers
Readme
electron-use-ipc-listener
React Hook for Electron that simplifies IPC routine.
For usage in Renderer process.
Usage
Send a message from Main process as usual.
// main/index.js
const {app, BrowserWindow} = require('electron');
let win = null
app.whenReady().then(() => {
win = new BrowserWindow({width: 800, height: 600});
win.loadURL(`file://${__dirname}/index.html`);
win.webContents.send('messageFromMain', 'whoo', 'hoo');
});
Use useIpcListener
custom hook to handle message.
// renderer/components/MyComponent.js
import React from 'react';
import useIpcListener from 'useIpcListener';
const MyComponent = () => {
useIpcListener('messageFromMain', ((event, ...args) => {
console.log('Received message from Main Process', ...args)
}));
};
Inspired by @use-it/event-listener