update reactjs from electronjs

Solutions on MaxInterview for update reactjs from electronjs by the best coders in the world

showing results for - "update reactjs from electronjs"
Victor
26 Aug 2018
1//main.js
2ipcMain.on("download", (event, info) => {
3info.properties.onProgress = status => win.webContents.send("downloadProgress", status);
4  });
5
6//preload.js
7contextBridge.exposeInMainWorld('electron', {
8  api: {
9    responseProgress: (channel, func) => {
10        let validChannels = ["downloadProgress"];
11        if (validChannels.includes(channel)) { 
12        	ipcRenderer.on(channel, (event, ...args) => func(...args));
13        }
14    },
15});
16  
17//ReactComponent.js
18  function ReactComponent() {
19  useEffect(() => {
20        window.electron.api.responseProgress("downloadProgress", (progress) => {
21        console.log(progress);
22        console.log(progress.percent);
23        });
24          }, []);
25  return (
26    <button onClick={() => {
27    //example of calling api on button click
28      window.electron.api.process("toMain");
29    }}>Download</button>
30    )
31}