Reputation: 487
I'd like to know how to send several arguments via ipcRenderer on an Electron app. Should I send an array of arguments or just all the arguments separated by comma?
Thanks,
Upvotes: 11
Views: 19134
Reputation: 342
We can pass many arguments for the ipcRenderer, you can refer this page: https://electronjs.org/docs/api/ipc-renderer.
Upvotes: 0
Reputation: 5531
Docs clearly shows that you can pass any number of argument to send
.
Send a message to the main process asynchronously via channel, you can also send arbitrary arguments. Arguments will be serialized in JSON internally and hence no functions or prototype chain will be included.
From that point on you have no restrictions on how to use those arbitrary arguments. It depends on your needs, your codebase style etc.
Upvotes: 3
Reputation: 1157
I would recommend an object for parameter transfer. In consequence, you can also think about implementing a consistent API for your application:
var _myreq = {
state: 0, //0 is no error, 4 is error with message, etc.
message: "", //can include error message (if any)
data: [0,4,6] //application data for request (String, Array, Object)
};
ipc.send('mychannel-functiona', _myreq);
Upvotes: 13