YesPlayMusic/packages/web/hooks/useIpcRenderer.ts
2022-06-25 13:47:07 +08:00

14 lines
353 B
TypeScript

import { IpcChannels, IpcChannelsReturns } from '@/shared/IpcChannels'
import { useEffect } from 'react'
const useIpcRenderer = <T extends IpcChannels>(
channel: T,
listener: (event: any, value: IpcChannelsReturns[T]) => void
) => {
useEffect(() => {
return window.ipcRenderer?.on(channel, listener)
}, [])
}
export default useIpcRenderer