Hi, I’m trying to define a variable on electron main process and read it from a renderer process. My application was started following this guide. It was created using create-react app and renaming main.js to electron-starter.js.
At the end of my electron-starter.js file (main process) I added the line
global.hello = "hello"
and in my index.js file I tried this
const remote = window.require('electron').remote; console.log(remote.getGlobal('hello'))
I have to use window.require so webpack does not mess up the imports. This returns undefined in the dev console. I think remote is working cause I can do
and it will show the function. It seems I can’t set/read globals, is there anything else I should do?
I was trying to use node-sqlite3, which doesn’t work with webpack, so my plan was implementing the functions that use sqlite3 on electron main process and sharing them with the renderer so the react components can use them, without having to eject from CRA and messing with webpack configs.
Even if I can make remote work, Is it a good solution to share those functions?