YesPlayMusic/packages/web/hooks/useIpcRenderer.ts

14 lines
353 B
TypeScript
Raw Normal View History

2022-06-25 13:47:07 +08:00
import { IpcChannels, IpcChannelsReturns } from '@/shared/IpcChannels'
import { useEffect } from 'react'
2022-06-25 13:47:07 +08:00
const useIpcRenderer = <T extends IpcChannels>(
channel: T,
listener: (event: any, value: IpcChannelsReturns[T]) => void
) => {
useEffect(() => {
2022-06-25 13:47:07 +08:00
return window.ipcRenderer?.on(channel, listener)
}, [])
}
export default useIpcRenderer