Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
How to send events from electron to react components only after all components are ready?

I have an electron app and I'm trying to use ReactJs with it. I have code in main.js that sends some data on dom-ready event:

mainWindow.webContents.on('dom-ready', function () {
    dao.getIncomes(function (data) {
        mainWindow.webContents.send('income-data', data);
    });
}

Then I have React component, where I'm trying to set a listener for this event:

useEffect(() => {
    ipcRenderer.on('income-data', function (event, data) {
        // some code
    });
}, []);

Sometimes, a component init this effect only when the event has already sent. And listener doesn't receive this data.

How do I set the listener correctly in this case? O may be I should send events later, on some other event, instead of dom-ready

Thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think first you should tell the electron the function in effect is being Execute。

const { ipcMain } = require('electron')
ipcMain.on('react-effect-executed', (event, arg) => {
  dao.getIncomes(function (data) {
    mainWindow.webContents.send('income-data', data);
  });
})

useEffect(() => {
    ipcRenderer.send('react-effect-executed', '');
    ipcRenderer.on('income-data', function (event, data) {
        // some code
    });
}, []);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!