Is this the way to call ipcRenderer in react-electron app

Viewed 79

I would like to call ipcRenderer.send function when I click the button.

Is my method appropriate?

Any helps and suggestions will be appreciated!

my way (client side) :

function App() {
  useEffect(() => {

document.getElementById('test')
  .addEventListener('click',
    e => {
      ipcRenderer.send('runScript');

    })
    console.log(1)
 }, [])
  return (

 <>
  <button id='test'>hello</button>
 </>
)}

export default App

on Electron side:

ipcMain.on("runScript", (event, data) => {
exec("node helloworld.js", (error, stdout, stderr) => { 
     console.log(stdout);
     console.log(2)
 });
});

Best regards,

Jackson

0 Answers
Related