1

I'm new to Electron and I am clueless as to how to access the Electron's process object from my app.js component.

This is my function createWindow

function createWindow() {
  mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: { nodeIntegration: true },
  });
  mainWindow.loadURL("http://localhost:3000/");
  mainWindow.on("closed", function () {
    mainWindow = null;
  });
}

And this is my app.js component

class App extends React.Component {
  componentDidMount() {
    console.log("process", process);
  }

  render() {
    return <h1>Hello</h1>;
  }
}

At the moment, I am able to launch the app and the render app.js, but I can't access the process object from there.

Willy Carrera
  • 251
  • 1
  • 2
  • 10
  • ipcRenderer is a way to communicate between React and Electron. You can import it in your React side like this const ipcRenderer = require('electron').ipcRenderer. View this link https://stackoverflow.com/a/40251412/7645527 – oakar Apr 07 '20 at 08:41

1 Answers1

3

After trying multiple things, this simple solution worked:

componentDidMount() {
    console.log("process", window.process);
  }
Willy Carrera
  • 251
  • 1
  • 2
  • 10