saltyshiomix / nextron

⚡ Next.js + Electron ⚡
https://npm.im/nextron
MIT License
3.69k stars 215 forks source link

How to remove window.ipc.on listener? #465

Open pengxueshan opened 1 month ago

pengxueshan commented 1 month ago

I use window.ipc.on in useEffect, but the listener still called after the component unmounted

footcoderr commented 4 weeks ago

There are many ways, but this is how I write :)

  1. Add to preload.ts removeAllListeners: (action: string) => { ipcRenderer.removeAllListeners(action); },

  2. Add topreload.d.ts removeAllListeners: (action: string) => void;

  3. Then call this when the component is unmounted in useEffect. return () => { window.ElectronAPI.removeAllListeners('auth-result'); };