YesPlayMusic/packages/web/hooks/useIpcRenderer.ts
2022-05-12 02:45:43 +08:00

14 lines
373 B
TypeScript

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