IPC Communication Between Processes
Use ipcMain and ipcRenderer to send messages between the main process and React renderer securely.
ipcMain.handle: Request-Response Pattern
ipcMain.handle registers a named channel in the main process that responds to requests from the renderer. It accepts an async handler function and its return value becomes the resolved value of the Promise in the renderer, making it ideal for operations like reading files or querying a database.
ipcRenderer.invoke: Calling the Main Process
ipcRenderer.invoke sends a message on a named channel and returns a Promise that resolves with the main process handler's return value. This creates a clean async request-response pattern that works naturally with async/await in both the preload script and React components.
All lessons in this course
- Electron Architecture: Main and Renderer Processes
- Setting Up React with Electron
- IPC Communication Between Processes
- Packaging and Distribution for Desktop Platforms