docs: moves icpMain.handle call in tutorial part 3 (#38138)

This commit is contained in:
Russell Carpenella 2023-05-03 08:52:02 -04:00 committed by GitHub
parent a8c0ed890f
commit 7f5364f98d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -202,7 +202,7 @@ Then, set up your `handle` listener in the main process. We do this _before_
loading the HTML file so that the handler is guaranteed to be ready before
you send out the `invoke` call from the renderer.
```js {1,12} title="main.js"
```js {1,15} title="main.js"
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
@ -214,10 +214,12 @@ const createWindow = () => {
preload: path.join(__dirname, 'preload.js'),
},
})
ipcMain.handle('ping', () => 'pong')
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
app.whenReady().then(() => {
ipcMain.handle('ping', () => 'pong')
createWindow()
})
```
Once you have the sender and receiver set up, you can now send messages from the renderer