Use the ipcMain and ipcRenderer modules to communicate between Electron processes
#Send Data from Main to Renderer through Preload
14 messages · Page 1 of 1 (latest)
I check out this but still unable to do this .
Here is my main.js
ipcMain.on('getMainValue', (event) => {
const mainValue = 'Hello from Main Value'
event.sender.send('mainValue', mainValue)
})
preload.js
contextBridge.exposeInMainWorld('EAPI', {
getMainValue: () => {
return new Promise((resolve, _reject) => {
ipcRenderer.send('getMainValue')
ipcRenderer.once('mainValue', (event, mainValue) => {
resolve(mainValue)
})
})
}
})
App.js
const [mainValue, setMainValue] = useState('')
useEffect(() => {
const getFromMain = async () => {
try {
const value = await window.EAPI.getMainValue()
setMainValue(value)
console.log(value)
} catch (error) {
console.log(error)
}
}
getFromMain()
}, [])
I got the value from main to rendere but not at the application load time. When I save my application second time I received the value, maybe some synchonization issues.
Load time?
Yes
What is it?
I mean when application run for the first time
I don't see any code related to that
In your example
And use handle/invoke
If you need return value
Like request/response
Actually I don't need any return value, It should be one way data passing .