Send data between Electron App and React JS App

--

Send data from React to electron and get data from Electron

Below code need to be add in React js to send an event to the electron app

const { ipcRenderer } = window.require(“electron”);

export const sendData = data => {

ipcRenderer.send(“send-data-event-name”, JSON.stringify(data));

};

ipcRenderer.on(“send-data-event-name-reply”, (event, arg) => {

console.log(arg);

});

Below code need to add in the electron.js file to receive the event

const { ipcMain } = require(“electron”);

ipcMain.on(“send-data-event-name”, (event, data) => {

// here we can process the data

// we can send reply to react using below code

event.reply(“send-data-event-name-reply”, ‘Hey react app processed your event’);

});

--

--