-2

I am using electron version 2.0.5 and ipcMain and ipcRenderer to pass data between my HTML and my main.js

let fna,lna,emaila,passa;
ipcMain.on('fname', function(er, fn){
  fna = fn;
  console.log(fn)
});

console.log(fna);

When I test it the function runs and when the first console.log runs. I get the right data. But when the second one runs I get undefined... I do not understand electron very well as I am new to it.

Thank you in advance.

Snips YT
  • 131
  • 1
  • 8
  • Also see: https://stackoverflow.com/questions/51619966/how-to-call-a-function-with-a-promise and https://stackoverflow.com/questions/51619394/asynchronous-behavior-of-functions-in-typescript – lealceldeiro Aug 07 '18 at 19:07

1 Answers1

0

Your second log (fna) is called before the ipcMain.on is called, so it has not been assigned yet.

Steven Spungin
  • 27,002
  • 5
  • 88
  • 78