Sending data from main process to React (rendered process)


#1

Hi, I’m playing with electron trying to wrap an old demo I did with React.
I’m trying to understand how to pass the content of a file I open with the menu API to the rendered process.
Is Webcontents.send() the only way to do it? Or maybe is there a solution to pass directly to my app.jsx the content of the file?


#2

Hello there, I think what you are looking for is ipc. I’m using it to pass data / send events from the rendered process to the main process but I’m pretty sure it can be done the other way arround. Have a look at the docs for ipc.


#3

Hey @ekonstantinidis I finally solved using win.send('fileContent', data); in the main process and

       this.setState({
        content: fileData
      });
    });```
in the rendered process as you suggested me.

I was struggling because I was unable to import the ipc module in the rendered process. This because of the way I tried to get React, ES6 and Electron work together. 
[This post][1] was really helpful to understand how to solve this part.


  [1]: http://go.shr.lc/1PQPYxA