Event listeners in React / Redux in a separate file (electron)
So I have a React / electronic application. Sometimes my file main.js
sends some data via ipc. So far I have had React components to send and wait for specific ipc events like:
constructor(props) {
super(props);
ipcRenderer.send('sendTranslateRequest', "Bonjour mon amour");
ipcRenderer.on('receiveTranslateResponse', (evt, arg) => {
//... });
}
However, since I am using Redux, I have now found myself to be a little more about the architecture of my applications. It wouldn't be a good idea to create a separate file and put all my listeners in it, and whenever the listener gets activated dispatch a Redux action. Likewise, to have all of mine ipcRenderer.send
included in their respective Redux activities, so that my React components are completely gone from it all?
Is it possible? Q: Would that be a good idea?
I am wondering how I can create a file that can take all my listeners. So I would have a file like this:
ipcRenderer.on('receiveTranslateResponse', (evt, arg) => {
//dispatch actions then
});
ipcRenderer.on('receiveAnotherResponse', (evt, arg) => {
//dispatch actions then
});
I don't understand how to include this file in my React app, how and where to execute it?
source to share
No one has answered this question yet
Check out similar questions: