admin管理员组文章数量:1022533
Say I want to build a simple file explorer Electron app, and design the UI with React. Now, I need React to send the appropriate IPC calls from a Component to the main process of Electron, and receive replies containing filenames for the File explorer that is rendered by React.
How do I go about doing it? There are unfortunately no recent tutorials for this.
Say I want to build a simple file explorer Electron app, and design the UI with React. Now, I need React to send the appropriate IPC calls from a Component to the main process of Electron, and receive replies containing filenames for the File explorer that is rendered by React.
How do I go about doing it? There are unfortunately no recent tutorials for this.
Share Improve this question asked Jul 1, 2021 at 11:02 Sohail SahaSohail Saha 5732 gold badges7 silver badges18 bronze badges 6- It's documented here. There are also examples electronjs/docs/api/ipc-main – Tracer69 Commented Jul 1, 2021 at 11:04
- and here's a db example using contextIsolation and IPC – pilchard Commented Jul 1, 2021 at 11:06
- @Tracer69 I know about using the 'ipcMain' and 'ipcRenderer' modules. My question was, how do I access them from within a React rendered UI. – Sohail Saha Commented Jul 1, 2021 at 11:08
-
Through the
ipcRenderer
exported by theelectron
package (as stated in the example) – Tracer69 Commented Jul 1, 2021 at 11:09 - @pilchard Thanks a lot. That was exactly what I needed! – Sohail Saha Commented Jul 1, 2021 at 11:19
1 Answer
Reset to default 4So, @pilchard's ment pointed me to a blog post titled Creating standalone Desktop Applications with React, Electron and SQLite3, and that finally gave me the best answer.
You use what is called a contextBridge
, use it to create a api to bridge the renderer process and main process, and expose only the needed functions. Read the post I mentioned above (scroll down to the 'Communication Between React & Electron' section), and you'll get it.
Say I want to build a simple file explorer Electron app, and design the UI with React. Now, I need React to send the appropriate IPC calls from a Component to the main process of Electron, and receive replies containing filenames for the File explorer that is rendered by React.
How do I go about doing it? There are unfortunately no recent tutorials for this.
Say I want to build a simple file explorer Electron app, and design the UI with React. Now, I need React to send the appropriate IPC calls from a Component to the main process of Electron, and receive replies containing filenames for the File explorer that is rendered by React.
How do I go about doing it? There are unfortunately no recent tutorials for this.
Share Improve this question asked Jul 1, 2021 at 11:02 Sohail SahaSohail Saha 5732 gold badges7 silver badges18 bronze badges 6- It's documented here. There are also examples electronjs/docs/api/ipc-main – Tracer69 Commented Jul 1, 2021 at 11:04
- and here's a db example using contextIsolation and IPC – pilchard Commented Jul 1, 2021 at 11:06
- @Tracer69 I know about using the 'ipcMain' and 'ipcRenderer' modules. My question was, how do I access them from within a React rendered UI. – Sohail Saha Commented Jul 1, 2021 at 11:08
-
Through the
ipcRenderer
exported by theelectron
package (as stated in the example) – Tracer69 Commented Jul 1, 2021 at 11:09 - @pilchard Thanks a lot. That was exactly what I needed! – Sohail Saha Commented Jul 1, 2021 at 11:19
1 Answer
Reset to default 4So, @pilchard's ment pointed me to a blog post titled Creating standalone Desktop Applications with React, Electron and SQLite3, and that finally gave me the best answer.
You use what is called a contextBridge
, use it to create a api to bridge the renderer process and main process, and expose only the needed functions. Read the post I mentioned above (scroll down to the 'Communication Between React & Electron' section), and you'll get it.
本文标签: javascriptElectron Send IPC messages from React to Electron main processStack Overflow
版权声明:本文标题:javascript - Electron: Send IPC messages from React to Electron main process? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745524905a2154479.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论